提交时间:2025-10-23 19:55:55
运行 ID: 38752
#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define p_b push_back using namespace std; typedef long long ll; typedef long double db; const int maxn=2e5+10; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } int k,n,q,x[15],y[15];ll res[maxn]; struct{int p,q,t;}a[maxn]; struct{int x,y,w;}d[maxn]; struct fc{ll p,q;fc(ll _p,ll _q){p=_p,q=_q;if(q<0)p=-p,q=-q;}fc(){}}; bool operator<(fc a,fc b){return a.p*b.q<b.p*a.q;} fc operator*(fc a,fc b){return fc(a.p*b.p,a.q*b.q);} fc operator+(fc a,fc b){return fc(a.p*b.q+a.q*b.p,a.q*b.q);} fc operator-(fc a,fc b){return fc(a.p*b.q-a.q*b.p,a.q*b.q);} struct node{ fc w;int id,l,r; }b[maxn]; bool operator<(node a,node b){ return m_p(a.w,a.id)<m_p(b.w,b.id); } struct BIT { int n;ll t[maxn]; void clear(){up(i,1,n)t[i]=0;} int lb(int x){return x&(-x);} void upd(int x,int v){for(;x<=n;x+=lb(x))t[x]+=v;} ll ask(int x){ll res=0;for(;x;x-=lb(x))res+=t[x];return res;} }T; namespace _{ int x[maxn],y[maxn]; int w[maxn]; void slv(int S){ map<int,vector<pair<int,ll> > >mp; up(i,1,n)x[i]=read(),y[i]=read(),w[i]=read(),mp[y[i]].p_b({x[i],w[i]}); for(auto &it:mp){ sort(it.p2.begin(),it.p2.end()); ll s=0;for(auto &x:it.p2)s+=x.p2,x.p2=s; } while(q--){ int x=read(),y=read(),T=read(); auto qr=[&](int k){ if(!mp.count(y))return 0ll; auto it=lower_bound(mp[y].begin(),mp[y].end(),(pair<int,ll>){k+1,-1ll}); if(it==mp[y].begin())return 0ll; return (*(--it)).p2; }; printf("%lld\n",qr(x+T*S)-qr(x-T*S-1)); } } } void slv(){ k=read(),n=read(),q=read(); int S=0,tot=0; up(i,1,k){ x[i]=read(),y[i]=read(); if(x[i]<0)x[i]=-x[i],y[i]=-y[i]; else if(!x[i])y[i]=abs(y[i]),S+=y[i]; tot+=x[i]!=0; } if(!tot){_::slv(S);return;} up(i,1,n)d[i].x=read(),d[i].y=read(),d[i].w=read(); up(i,1,q){ int p=read(),q=read(),T=read(); up(j,1,k)p-=T*x[j],q-=T*y[j];T<<=1; a[i]={p,q,T}; } vector<pi>v; up(i,1,k)if(x[i])v.p_b({x[i],y[i]}); sort(v.begin(),v.end(),[&](pi a,pi b){return b.p1*a.p2>b.p2*a.p1;}); // printf("v:");for(auto it:v)printf("(%d,%d),",it.p1,it.p2);putchar(10); auto work=[&](int sx,int sy,int sgn){ up(i,0,(int)v.size()-1){ fc k(v[i].p2,v[i].p1); vector<int>vc; up(j,1,n){ fc y=fc(d[j].y,1)-(fc(d[j].x,1)*k); b[j].w=y,b[j].id=-j*sgn,b[j].l=d[j].x,b[j].r=d[j].w; vc.p_b(b[j].l); } up(j,1,q){ int nl=a[j].p+sx*a[j].t,nr=a[j].p+(sx+v[i].p1)*a[j].t; b[j+n].w=fc(a[j].q,1)+fc(sy*a[j].t,1)-fc(nl,1)*k,b[j+n].id=j*sgn; b[j+n].l=nl,b[j+n].r=nr-1; if(i==(int)v.size()-1)b[j+n].r++; vc.p_b(b[j+n].l-1),vc.p_b(b[j+n].r); } sort(vc.begin(),vc.end()); vc.erase(unique(vc.begin(),vc.end()),vc.end()); up(j,1,n+q){ b[j].l=lower_bound(vc.begin(),vc.end(),b[j].l)-vc.begin()+1; if(j>n)b[j].r=lower_bound(vc.begin(),vc.end(),b[j].r)-vc.begin()+1; } T.n=vc.size();T.clear(); sort(b+1,b+n+q+1); up(i,1,n+q){ if(b[i].id/abs(b[i].id)!=sgn)T.upd(b[i].l,b[i].r); else res[abs(b[i].id)]+=sgn*(T.ask(b[i].r)-T.ask(b[i].l-1)); } sx+=v[i].p1,sy+=v[i].p2; } }; work(0,S,1); reverse(v.begin(),v.end()); work(0,0,-1); up(i,1,q)printf("%lld\n",res[i]); } int main(){ //freopen("spy.in","r",stdin),freopen("spy.out","w",stdout); slv(); return 0; }