fork download
  1. // ~~ icebear ~~
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7. typedef pair<int, ii> iii;
  8.  
  9. template<class T>
  10. bool minimize(T &a, const T &b) {
  11. if (a > b) return a = b, true;
  12. return false;
  13. }
  14.  
  15. template<class T>
  16. bool maximize(T &a, const T &b) {
  17. if (a < b) return a = b, true;
  18. return false;
  19. }
  20.  
  21. #define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
  22. #define FORR(i,a,b) for(int i=(a); i>=(b); --i)
  23. #define REP(i, n) for(int i=0; i<(n); ++i)
  24. #define RED(i, n) for(int i=(n)-1; i>=0; --i)
  25. #define MASK(i) (1LL << (i))
  26. #define BIT(S, i) (((S) >> (i)) & 1)
  27. #define mp make_pair
  28. #define pb push_back
  29. #define fi first
  30. #define se second
  31. #define all(x) x.begin(), x.end()
  32. #define task "icebear"
  33. /*END OF TEMPLATE. ICEBEAR AND THE CAT WILL WIN VOI26 */
  34.  
  35. const int MOD = 1e9 + 7;
  36. const int inf = 1e9 + 27092008;
  37. const ll INF = 1e18 + 27092008;
  38. const int N = 2e5 + 5;
  39. int numType, numStation, perCost, pos[N], cost[N];
  40.  
  41. void init(void) {
  42. cin >> numType >> numStation >> perCost;
  43. FOR(i, 1, numStation) cin >> pos[i] >> cost[i];
  44. }
  45.  
  46. void process(void) {
  47. if (numType == 1) {
  48. map<ll, int> cnt;
  49. ll ans = 0;
  50. FOR(i, 1, numStation) {
  51. ans += cnt[1LL * pos[i] * perCost - cost[i]];
  52. cnt[cost[i] + 1LL * pos[i] * perCost]++;
  53. }
  54. cout << ans % MOD;
  55. } else {
  56. auto power = [&](int x, int k) {
  57. int res = 1;
  58. while(k) {
  59. if (k & 1) res = 1LL * res * x % MOD;
  60. k >>= 1;
  61. x = 1LL * x * x % MOD;
  62. }
  63. return res;
  64. };
  65. map<ll, int> sum;
  66. ll ans = 0;
  67. FOR(i, 1, numStation) {
  68. (ans += 1LL * power(2, i) * sum[1LL * pos[i] * perCost - cost[i]]) %= MOD;
  69. (sum[1LL * pos[i] * perCost + cost[i]] += power(power(2, i + 1), MOD - 2)) %= MOD;
  70. }
  71. cout << ans;
  72. }
  73. }
  74.  
  75. int main() {
  76. ios_base::sync_with_stdio(0);
  77. cin.tie(0); cout.tie(0);
  78. if (fopen(task".inp", "r")) {
  79. freopen(task".inp", "r", stdin);
  80. freopen(task".out", "w", stdout);
  81. }
  82. int tc = 1;
  83. // cin >> tc;
  84. while(tc--) {
  85. init();
  86. process();
  87. }
  88. return 0;
  89. }
  90.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty