比赛 2024暑期C班集训2 评测结果 AATTTTTTTT
题目名称 Vera 与现代艺术 最终得分 20
用户昵称 ┭┮﹏┭┮ 运行时间 16.125 s
代码语言 C++ 内存使用 14.89 MiB
提交时间 2024-07-02 11:40:23
显示代码纯文本
#include <bits/stdc++.h> 
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define mp make_pair
#define in inline
#define re register
const int N = 2e5+10;
const ll mod = 1e9+7;


in ll read(){
   ll x = 0,f = 1;char c = getchar();
   for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
   for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
   return x * f;
}

int n,m;
struct made{
    ll x,y,v,a,b;
}a[N];
ll lowbit(ll x){return x & (-x);}
ll find(ll x){
    while(x != lowbit(x))x -= lowbit(x);
    return x;
}
ll ans[N];
map<pii,ll>p;
int main(){
    freopen("modern.in","r",stdin);
    freopen("modern.out","w",stdout);
    n = read(),m = read();
    p.clear();
    for(re int i = 1;i <= n;i++)a[i].x = read(),a[i].y = read(),a[i].v = read(),a[i].a = find(a[i].x),a[i].b = find(a[i].y);
    if(n <= 2000){
        for(int i = 1;i <= m;i++){
            ll r = read(),c = read();
            for(int j = 1;j <= n;j++)
            if((r - a[j].x) % a[j].a == 0 && (c - a[j].y) % a[j].b == 0)ans[i] += a[j].v;
        }
        for(int i = 1;i <= m;i++)printf("%lld\n",ans[i]);
        return 0;
    }
    for(re int i = 1;i <= n;i++)p[mp(a[i].x,a[i].y)] += a[i].v;
    for(re int i = 1;i <= m;i++){
        ll r = read(),c = read();
        for(re int j = 0;j <= 60;j++)
            for(re int k = 0;k <= 60;k++){
                ll m1 = (1ll<<j),m2 = (1ll<<k);
                ans[i] += p[make_pair(r%m1+m1,c%m2+m2)];
            }
    }
    for(re int i = 1;i <= m;i++)printf("%lld\n",ans[i]);
    
    
    return cerr<<clock()<<"ms"<<endl,0;
}