Submission #1349691

#TimeUsernameProblemLanguageResultExecution timeMemory
1349691mishasimVera and Modern Art (CCO17_art)C++20
15 / 25
4094 ms13344 KiB
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'

struct HashPair {
    size_t operator()(const pair<long long, long long>& p) const {
        return p.first * 31 + p.second;
    }
};

unordered_map<pair<long long, long long>, long long, HashPair> m[61][61];

long long n, q, x, y, v, res;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> q;

    for (int i = 1; i <= n; i++) {
        cin >> x >> y >> v;

        int lx = 63 - __builtin_clzll(x);
        int ly = 63 - __builtin_clzll(y);

        long long rx = x % (1LL << lx);
        long long ry = y % (1LL << ly);

        m[lx][ly][{rx, ry}] += v;
    }

    for (int i = 1; i <= q; i++) {
        cin >> x >> y;
        res = 0;

        for (int lx = 0; lx <= 60; lx++) {
            if ((1LL << lx) > x) break;

            long long rx = x % (1LL << lx);

            for (int ly = 0; ly <= 60; ly++) {
                if ((1LL << ly) > y) break;

                long long ry = y % (1LL << ly);

                auto it = m[lx][ly].find({rx, ry});
                if (it != m[lx][ly].end()) {
                    res += it->second;
                }
            }
        }

        cout << res << endl;
    }

    return 0;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...