Advertisement
nicuvlad76

Untitled

Feb 21st, 2023
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("transport.in");
  7. ofstream fout("transport.out");
  8.  
  9. const int modulo = 1e9 + 7;
  10.  
  11. struct magistrala {
  12. int x, d;
  13. }v[200005];
  14.  
  15. map<ll, int> ma;
  16.  
  17. long long binpow(long long a, long long b, long long m) {
  18. a %= m;
  19. ll res = 1;
  20. while (b > 0) {
  21. if (b & 1) {
  22. res = res * a % m;
  23. }
  24. a = a * a % m;
  25. b >>= 1;
  26. }
  27. return res;
  28. }
  29.  
  30. int main() {
  31. int cer, n, c; fin >> cer >> n >> c;
  32. for(int i = 1; i <= n; i++) {
  33. fin >> v[i].x >> v[i].d;
  34. }
  35. if(cer == 1) {
  36. ll rez = 0;
  37. for(int i = 1; i <= n; i++) {
  38. rez += ma[c * v[i].x - v[i].d];
  39. rez %= modulo;
  40. ma[c * v[i].x + v[i].d]++;
  41. }
  42. fout << rez;
  43. return 0;
  44. }
  45. if(cer == 2) {
  46. ll rez = 0;
  47. for(int i = 1; i <= n; i++) {
  48. ll ii = binpow(2, i, modulo);
  49. rez = (rez + (ii * ma[c * v[i].x - v[i].d])) % modulo;
  50. ii = binpow(2, i+1, modulo);
  51. ma[c * v[i].x + v[i].d] = (ma[c * v[i].x + v[i].d] + binpow(ii, modulo-2, modulo)) % modulo;
  52. }
  53. fout << rez;
  54. }
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement