제출 #1349604

#제출 시각아이디문제언어결과실행 시간메모리
1349604mishasimVera and Modern Art (CCO17_art)C++20
5 / 25
2802 ms9876 KiB
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
unordered_map<long long, long long> m[61][61];
long long n, q, x, y, v, res;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    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 key = (x % (1LL << lx) << 32) | (y % (1LL << ly));
        m[lx][ly][key] += v;
    }
    for(int i = 1 ; i<=q ; i++){
        res = 0;
        cin>>x>>y;
        for(int lx = 0; (1LL << lx) <= x; lx++){
            long long rx = x % (1LL << lx);
            for(int ly = 0; (1LL << ly) <= y; ly++){
                long long ry = y % (1LL << ly);
                long long key = (rx << 32) | ry;
                if(m[lx][ly].count(key)) res += m[lx][ly][key];
            }
        }
        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...