记录编号 |
589030 |
评测结果 |
AAAAAAAAAA |
题目名称 |
Vera 与现代艺术 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
2.943 s |
提交时间 |
2024-07-02 16:39:40 |
内存使用 |
154.98 MiB |
显示代码纯文本
#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,cnt,len;
ll c[N<<4];
struct node{
ll x,y,v,a,b;
}a[N];
struct made{
ll l,r,v,now;int id;
bool operator < (const made x)const{
if(now != x.now)return now < x.now;
return id < x.id;
}
}q[N<<4];
struct BIT{
ll c[N<<4];
int lowbit(int x){return x & (-x);}
void add(int x,ll val){for(;x <= len;x += lowbit(x))c[x] += val;}
void add(int l,int r,ll val){add(l,val),add(r+1,-val);}
ll ask(int x){
ll ans = 0;
for(;x > 0;x -= lowbit(x))ans += c[x];
return ans;
}
}t;
ll ans[N];
void prin(ll x){
for(int i = 0;i <= 60;i++){
cout<<x % 2;
x >>= 1;
}
cout<<endl;
}
ll rev(ll x){
ll ans = 0;
for(int i = 60,j = 0;j <= 60;j++,i--){
ans += ((x & (1ll<<j))>>j)<<i;
// prin(ans);
}
return ans;
}
ll lowbit(ll x){return x & (-x);}
int main(){
freopen("modern.in","r",stdin);
freopen("modern.out","w",stdout);
n = read(),m = read();
for(re int i = 1;i <= n;i++)a[i].x = rev(read()),a[i].y = rev(read()),a[i].v = read();
for(int i = 1;i <= n;i++){
a[i].a = lowbit(a[i].x),a[i].b = lowbit(a[i].y);
q[++cnt] = {a[i].y-a[i].b+1,a[i].y+a[i].b-1,a[i].v,a[i].x-a[i].a+1,0};
q[++cnt] = {a[i].y-a[i].b+1,a[i].y+a[i].b-1,-a[i].v,a[i].x+a[i].a-1 + 1,0};
c[++len] = a[i].y + a[i].b - 1;
c[++len] = a[i].y - a[i].b + 1;//离散化
}
for(int i = 1;i <= m;i++){
ll r = rev(read()),c1 = rev(read());
q[++cnt] = {c1,0,0,r,i};
c[++len] = c1;
}
sort(c+1,c+1+len);
len = unique(c+1,c+1+len) - (c+1);
for(int i = 1;i <= cnt;i++){
q[i].l = lower_bound(c+1,c+1+len,q[i].l) - c;
q[i].r = lower_bound(c+1,c+1+len,q[i].r) - c;
}
sort(q+1,q+1+cnt);
for(int i = 1;i <= cnt;i++){
if(!q[i].id)t.add(q[i].l,q[i].r,q[i].v);
else ans[q[i].id] = t.ask(q[i].l);
}
for(int i = 1;i <= m;i++)printf("%lld\n",ans[i]);
return cerr<<clock()<<"ms"<<endl,0;
}