Submission #1349568

#TimeUsernameProblemLanguageResultExecution timeMemory
1349568mishasimVera and Modern Art (CCO17_art)C++20
0 / 25
4111 ms738896 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;
long long step(long long nn){
    long long res1 = 1;
    for(int i = 1 ; i<=nn ; i++)res1*=2;
    return res1;
}
long long log(long long nn){
    long long ress = 0;
    while(nn>=2){
        nn/=2;
        ress++;
    }
    return ress;
}

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;
        long long key = (x%step(log(x)) << 32) | y%step(log(y));
        m[log(x)][log(y)][key]+=v;
    }
    for(int i = 1 ; i<=q ; i++){
        res = 0;
        cin>>x>>y;
        for(int xx = 0 ; xx<=60 ; xx++){
            for(int yy = 0 ; yy<=60 ; yy++){
                if((1LL << xx) <=x && (1LL << yy)<=y){
                        long long key = (x%(1LL << xx) << 32) | y%(1LL << yy);
                    res+=m[xx][yy][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...