제출 #1349572

#제출 시각아이디문제언어결과실행 시간메모리
1349572mishasimVera and Modern Art (CCO17_art)C++20
0 / 25
4115 ms747788 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;
        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 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...