Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- ifstream fin("transport.in");
- ofstream fout("transport.out");
- const int modulo = 1e9 + 7;
- struct magistrala {
- int x, d;
- }v[200005];
- map<ll, int> ma;
- long long binpow(long long a, long long b, long long m) {
- a %= m;
- ll res = 1;
- while (b > 0) {
- if (b & 1) {
- res = res * a % m;
- }
- a = a * a % m;
- b >>= 1;
- }
- return res;
- }
- int main() {
- int cer, n, c; fin >> cer >> n >> c;
- for(int i = 1; i <= n; i++) {
- fin >> v[i].x >> v[i].d;
- }
- if(cer == 1) {
- ll rez = 0;
- for(int i = 1; i <= n; i++) {
- rez += ma[c * v[i].x - v[i].d];
- rez %= modulo;
- ma[c * v[i].x + v[i].d]++;
- }
- fout << rez;
- return 0;
- }
- if(cer == 2) {
- ll rez = 0;
- for(int i = 1; i <= n; i++) {
- ll ii = binpow(2, i, modulo);
- rez = (rez + (ii * ma[c * v[i].x - v[i].d])) % modulo;
- ii = binpow(2, i+1, modulo);
- ma[c * v[i].x + v[i].d] = (ma[c * v[i].x + v[i].d] + binpow(ii, modulo-2, modulo)) % modulo;
- }
- fout << rez;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement