QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#94291 | #4409. 袜子 | Crysfly | 15 | 6956ms | 112104kb | C++17 | 5.3kb | 2023-04-05 16:59:04 | 2023-04-05 16:59:05 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define int long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f
int n,m;
#define i128 __int128
inline i128 ABS(i128 x){return x<0?-x:x;}
struct frac{
i128 x,y;
frac(){}
frac(i128 xx,i128 yy=1ll):x(xx),y(yy){
if(y<0)x=-x,y=-y;
}
friend frac operator +(frac a,frac b){return frac(a.x*b.y+a.y*b.x,a.y*b.y);}
friend frac operator -(frac a,frac b){return frac(a.x*b.y-a.y*b.x,a.y*b.y);}
friend frac operator *(frac a,frac b){return frac(a.x*b.x,a.y*b.y);}
friend frac operator /(frac a,frac b){return a*frac(b.y,b.x);}
friend bool operator <(frac a,frac b){return a.x*b.y<b.x*a.y;}
friend bool operator >(frac a,frac b){return a.x*b.y>b.x*a.y;}
friend bool operator <=(frac a,frac b){return !(a>b);}
friend bool operator >=(frac a,frac b){return !(a<b);}
friend bool operator ==(frac a,frac b){return a.x*b.y==b.x*a.y;}
friend bool operator !=(frac a,frac b){return !(a==b);}
frac operator - () {return frac(0)-x;}
};
struct P{
int x,y;
P(int x=0,int y=0):x(x),y(y){}
P&operator +=(P o){return x+=o.x,y+=o.y,*this;}
P&operator -=(P o){return x-=o.x,y-=o.y,*this;}
P&operator *=(int o){return x*=o,y*=o,*this;}
P&operator /=(int o){return x/=o,y/=o,*this;}
friend P operator +(P a,P b){return a+=b;}
friend P operator -(P a,P b){return a-=b;}
friend P operator *(P a,int b){return a*=b;}
friend P operator /(P a,int b){return a/=b;}
friend bool operator <(P a,P b){return a.x==b.x?a.y<b.y:a.x<b.x;}
friend int operator *(P a,P b){return a.x*b.x+a.y*b.y;} // dot
friend int operator %(P a,P b){return a.x*b.y-a.y*b.x;} // cross
};
struct point{
int x,y,c;
bool operator <(const point&b)const{return x<b.x||(x==b.x&&y<b.y);}
}p[maxn],a[maxn];
struct node{
int x,y; frac k;
node(int xx=0,int yy=0,frac kk=frac(0)){x=xx,y=yy,k=kk;}
friend bool operator <(node a,node b){
if(a.k!=b.k)return a.k<b.k;
if(a.x!=b.x)return a.x<b.x;
return a.y<b.y;
}
}t[1000005];
struct line{
frac k; int a,b,c,id;
friend bool operator <(line a,line b){return a.k<b.k;}
int F(int x,int y){return a*x+b*y+c;}
}q[500005];
int res[500005],resc[500005];
int B=1000;
int cnt,tot,pos[maxn],rev[maxn];
int l1[maxn],r1[maxn],c1[maxn],s1[maxn];
int l2[maxn],r2[maxn],c2[maxn],s2[maxn];
int lc,rc,prc;
int S(int x){return x*x;}
void upd1(int u){
s1[u]=s1[u-1]+S(c1[u])-S(c1[u]-1);
l1[u]=l1[u-1],r1[u]=r1[u-1];
if(a[u].c==lc) l1[u]=c1[u];
if(a[u].c==rc) r1[u]=c1[u];
}
void upd2(int v){
s2[v]=s2[v+1]+S(c2[v])-S(c2[v]-1);
l2[v]=l2[v+1],r2[v]=r2[v+1];
if(a[v].c==lc) l2[v]=c2[v];
if(a[v].c==rc) r2[v]=c2[v];
}
void upd(int x,int y){
// cout<<"upd "<<pos[x]<<" "<<pos[y]<<endl;
int u=pos[x],v=pos[y];
assert(abs(u-v)==1);
if(a[u].c!=a[v].c) swap(c1[u],c1[v]),swap(c2[u],c2[v]);
swap(a[u],a[v]);
upd1(u);
upd2(v);
swap(pos[x],pos[y]);
}
void work(int x,int y){
if(pos[x]>pos[y])return;
Rep(j,pos[y],pos[x]+1){
upd(rev[j-1],rev[j]);
swap(rev[j-1],rev[j]);
}
}
int col[maxn];
void init()
{
For(i,1,cnt) col[a[i].c]=0;
c1[0]=c2[0]=s1[0]=s2[0]=l1[0]=l2[0]=r1[0]=r2[0]=0;
int X=cnt+1;
c1[X]=c2[X]=s1[X]=s2[X]=l1[X]=l2[X]=r1[X]=r2[X]=0;
For(i,1,cnt){
++col[a[i].c];
c1[i]=col[a[i].c];
s1[i]=s1[i-1]+S(c1[i])-S(c1[i]-1);
l1[i]=l1[i-1],r1[i]=r1[i-1];
if(a[i].c==lc)l1[i]=c1[i];
if(a[i].c==rc)r1[i]=c1[i];
}
For(i,1,cnt) col[a[i].c]=0;
Rep(i,cnt,1){
++col[a[i].c];
c2[i]=col[a[i].c];
s2[i]=s2[i+1]+S(c2[i])-S(c2[i]-1);
l2[i]=l2[i+1],r2[i]=r2[i+1];
if(a[i].c==lc)l2[i]=c2[i];
if(a[i].c==rc)r2[i]=c2[i];
}
}
void solve(int bl,int br)
{
cnt=tot=0;
lc=p[bl].c,rc=p[br].c;
For(i,bl,br) a[++cnt]=p[i];
For(i,1,cnt) pos[i]=rev[i]=i;
sort(a+1,a+cnt+1);
For(i,1,cnt)
For(j,i+1,cnt)
if(a[i].x!=a[j].x)
t[++tot]=node(i,j,frac(a[j].y-a[i].y,a[j].x-a[i].x));
sort(t+1,t+tot+1);
init();
int j=1;
For(i,1,m){
while(j<=tot && t[j].k<q[i].k){
int x=t[j].x,y=t[j].y;
work(x,y);
++j;
}
int sum,sl,sr;
int l=1,r=cnt,id=q[i].id;
if(q[i].b>0){
int x=0;
while(l<=r){
int mid=l+r>>1;
if(q[i].F(a[mid].x,a[mid].y)<0)x=mid,l=mid+1;
else r=mid-1;
}
sum=s1[x],sl=l1[x],sr=r1[x];
}else{
int x=cnt+1;
while(l<=r){
int mid=l+r>>1;
if(q[i].F(a[mid].x,a[mid].y)<0)x=mid,r=mid-1;
else l=mid+1;
}
sum=s2[x],sl=l2[x],sr=r2[x];
}
if(prc!=lc) res[id]+=sum,resc[id]=sr;
else{
res[id]+=sum+S(resc[id]+sl)-S(sl)-S(resc[id]);
if(lc==rc)resc[id]+=sl;
else resc[id]=sr;
}
}
prc=rc;
}
signed main()
{
n=read(),m=read();
For(i,1,n)p[i].x=read(),p[i].y=read(),p[i].c=read();
sort(p+1,p+n+1,[&](point a,point b){return a.c<b.c||(a.c==b.c&&a<b);});
For(i,1,m){
int a=read(),b=read(),c=read();
q[i].k=frac(-a,b),q[i].id=i;
q[i].a=a,q[i].b=b,q[i].c=c;
}
sort(q+1,q+m+1);
for(int l=1;l<=n;l+=B) solve(l,min(n,l+B-1));
For(i,1,m)printf("%lld\n",res[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 88ms
memory: 73292kb
input:
1000 1000 8756 4483 237 -7891 -2818 114 8667 -7202 36 8150 -2 248 -4483 -9934 375 -9669 -1815 802 4008 9788 22 -2193 -4988 307 -9813 -4926 22 6344 8542 93 -9906 -9906 38 -3791 -2822 814 -7118 8408 51 -779 9589 3 -3211 1342 73 2346 -6502 112 31 -5037 6 3714 -4554 118 8788 6735 533 3860 -4232 5 3257 6...
output:
1047 1034 1001 1061 1060 956 1029 1001 1048 1001 1052 1023 1077 0 1077 1015 1060 1012 1022 1022 1077 1369 993 1001 1060 1003 1077 1034 1063 0 1001 1038 0 1001 1077 1001 1063 1063 1060 1034 0 1060 1060 1077 1031 1021 939 1023 849 1001 1060 1000 1008 1150 1007 878 1060 1060 1020 1043 1045 1077 1048 0 ...
result:
ok 1000 numbers
Test #2:
score: 0
Accepted
time: 97ms
memory: 73116kb
input:
1000 1000 -809378 594895 7 -463965 286585 108 492337 -110361 235 163858 -391125 15 -546105 -878318 214 360416 -730538 407 -298417 -177165 227 752631 -788118 51 17699 323971 105 843170 208717 105 766811 396573 69 127415 309072 39 637608 -188063 352 224425 -952868 139 850507 751278 110 -995626 648647 ...
output:
997 969 935 993 9 1023 998 1014 999 969 1001 982 1023 937 1028 1035 973 1029 953 969 25 1001 889 976 985 1023 937 1023 1006 992 937 1009 1023 969 969 1001 925 937 969 1001 969 1023 937 937 1000 1023 969 932 962 1001 969 994 937 1001 937 905 1008 937 1023 958 1023 1001 731 1015 956 988 945 970 1042 9...
result:
ok 1000 numbers
Test #3:
score: -5
Wrong Answer
time: 93ms
memory: 75460kb
input:
1000 1000 -329387625 -341019218 102 13965986 806087844 9 -528171131 227425809 15 786487633 15830440 3 539535861 -963497336 7 -742845817 -372626578 35 -787231340 -132749801 3 -543467667 -942295910 119 -672244153 -833463748 15 -641088972 317851104 1 65665573 -823079703 26 247807062 -882007619 11 -6610...
output:
4529 5025 4868 4426 3446 3771 3781 3700 4842 4604 4259 3557 3731 3538 3979 4367 4879 3595 4336 3446 4754 3632 3762 3750 3446 4879 4728 4668 4610 3781 4816 3600 3760 4868 3760 3446 4387 3446 3760 4529 4447 4019 4879 3781 3611 4529 4529 4865 4711 3446 4868 4104 3446 3760 3781 3387 4647 4736 4519 3730 ...
result:
wrong answer 276th numbers differ - expected: '3760', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 6956ms
memory: 109936kb
input:
50000 500000 384309433 -953786733 1 -381089810 891795502 1 -701194776 440247159 1 -403243027 539105336 1 275206790 -652250203 1 -554746251 903743804 1 -457035253 912757156 1 -342310772 -17612092 1 -440332191 682239316 1 730332275 816145283 1 -701691234 -908289789 1 -632861504 -277378843 1 -567495050...
output:
618496745 614079729 616866497 614478068 613189405 616715138 615126465 616114802 614529490 614077984 616764805 614626805 615475280 615176840 617956645 618705730 613485153 614626805 614626805 612802541 617062849 617662305 613684025 618496745 612900340 615420738 613682609 617857600 616568900 614626805 ...
result:
wrong answer 9301st numbers differ - expected: '619442473', found: '625000000'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #19:
score: 0
Wrong Answer
time: 5837ms
memory: 110192kb
input:
50000 500000 2598 -1000000 6 1388 -1000000 3 5492 1000000 8 -1000000 -3573 23 -1000000 -7880 15 -4285 1000000 7 1000000 5211 5 -1000000 5915 79 7147 -1000000 29 -9495 -1000000 25 9028 1000000 1 1000000 -4880 20 -8498 1000000 53 1000000 -4256 22 3107 -1000000 29 2061 -1000000 45 8876 -1000000 76 -279...
output:
12162691 12234856 12164084 12162691 12161484 12164084 12162691 12157836 12258260 12231963 12236398 12176350 12164084 12225490 12162691 12237049 12226003 12164084 12237262 12162691 12164084 12234856 12226003 12234856 12162691 12237049 48739336 12214677 12162691 12256061 12162691 12162691 12164084 122...
result:
wrong answer 5617th numbers differ - expected: '12225013', found: '14073596'
Subtask #5:
score: 15
Accepted
Test #25:
score: 15
Accepted
time: 6022ms
memory: 112104kb
input:
50000 500000 407 -5105 53 6211 98 81 7444 6196 1 -4294 -9353 26 4316 -3143 1 7144 2361 17 6364 -2245 14 -8684 -6564 3 6269 -687 2 -3139 5693 12 -9991 6547 20 2179 2178 47 -6588 7830 21 -6216 -200 3 9207 8834 24 9388 -5953 31 7752 4125 39 7875 -5517 22 -4701 2244 12 8088 3158 4 -4446 3467 1 -1002 154...
output:
10325005 11474809 0 0 11518032 0 0 49015742 49015742 49015742 0 11392831 0 49015742 0 13876057 0 13339251 10553686 49015742 49015742 49015742 14634637 0 0 49015742 49015742 0 11099497 49015742 11282162 0 0 49015742 0 49015742 0 49015742 49015742 49015742 0 49015742 13190125 13266876 0 0 10953869 116...
result:
ok 500000 numbers
Test #26:
score: 0
Accepted
time: 6214ms
memory: 110220kb
input:
50000 500000 -798827 -248238 55 -202385 195966 51 -935972 695372 12 -207494 597523 36 828639 839545 1 604085 -878258 28 854907 987889 33 -488652 555674 10 -308758 201373 2 786438 -72867 11 -533482 -614535 58 -853349 714523 60 729730 441018 27 193712 759574 30 -439466 -262414 1 -995124 383459 76 5638...
output:
12116545 1627120 12028488 8327000 11890527 12038075 12100532 30829152 23884384 48253618 0 0 48253618 12079058 4707441 34295749 1085217 12123770 48253618 20695368 11904819 3608287 12253559 0 12074236 12265677 12236373 48253618 12250929 0 11885547 11885547 7336386 12109428 48253618 0 0 36922388 511026...
result:
ok 500000 numbers
Test #27:
score: 0
Accepted
time: 5894ms
memory: 107952kb
input:
50000 500000 916228474 736861331 8 41223569 567024226 2 33633521 -640602439 11 43060388 157896754 9 522582493 -456464181 2 184581697 729182371 8 -915463955 774500464 2 595541741 4861507 3 375567184 -686285601 3 -59758078 -72014188 11 -535452680 -972290610 4 -425062848 998970443 3 776900364 383068694...
output:
73688076 34624304 35713642 74151261 74568055 73687317 80280672 73694989 74197031 74197031 190116467 73477393 74568055 23847839 86652478 126942497 108464771 74197031 125422244 56618750 74568055 73657436 9934358 85804146 74568055 221183265 178732347 73330257 73172655 74197031 73622903 74619669 7449609...
result:
ok 500000 numbers
Test #28:
score: 0
Accepted
time: 5939ms
memory: 109984kb
input:
50000 500000 -218467527 996547968 2 667898126 353067063 1 -703792310 -88011029 3 796101380 -150592337 1 233483304 202627437 1 227009907 -277641383 1 398753734 123601516 1 -932943038 -991506612 1 -586877275 884068330 1 -14924328 992992981 15 -558045242 470672933 7 -305045173 -532112183 7 183202586 80...
output:
34171044 145124721 133863158 322891322 149231859 144059207 201503200 147989909 145302374 145382184 145302231 144074835 144074694 186273717 391942339 147909184 145382184 147909184 45485862 30564622 147909184 13602211 29269333 136955300 161713859 145417496 411765627 144050978 147901245 147744158 30332...
result:
ok 500000 numbers
Test #29:
score: 0
Accepted
time: 5872ms
memory: 109952kb
input:
50000 500000 -209258179 -13673102 2 -536850965 -914833237 1 -859835086 -387099479 7 650316207 -949976551 2 490090099 432733293 1 295590818 336348152 1 -924146823 -481896977 1 -688990212 -402275949 1 905552333 225834084 1 100755207 -115968339 5 409919132 761133402 1 -486717813 -425455505 1 -448210451...
output:
342217921 351225756 335443425 351262509 109504291 342519167 344283077 344283077 335848738 803468818 538859665 335443425 344283077 344548834 351534475 335399668 765872733 216202376 344283077 335363755 351409541 51890336 201074052 335443425 351534475 335363755 351452899 124534601 342217921 351828683 3...
result:
ok 500000 numbers
Test #30:
score: 0
Accepted
time: 6195ms
memory: 107892kb
input:
50000 500000 -683034611 -711257501 27 60004722 -761142590 25 661166166 -468685357 7 849005124 -979617930 65 -844130034 690778896 26 420045533 -127259351 21 770352203 284425974 4 767529443 -311119877 25 -773073204 -708678356 61 -616770488 -127741421 27 -439194801 -804840917 7 -102517861 -591985498 15...
output:
5176455 36752777 12349440 9037077 11988285 12249163 12230497 6719556 12344687 12249163 11988285 12055113 31826512 12074401 15191922 32592923 12074401 12358058 10249606 12249163 11988285 12009512 12074401 12067085 11988285 12074401 12345034 12349440 12074401 11998182 12074401 23409470 1079840 2820121...
result:
ok 500000 numbers
Subtask #6:
score: 0
Skipped
Dependency #1:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%