QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#94285#4409. 袜子Crysfly0 6962ms110076kbC++175.3kb2023-04-05 16:54:172023-04-05 16:54:21

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-05 16:54:21]
  • 评测
  • 测评结果:0
  • 用时:6962ms
  • 内存:110076kb
  • [2023-04-05 16:54:17]
  • 提交

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),upd1(v);
	upd2(v),upd2(u);
	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)>>1;
				if(q[i].F(a[mid].x,a[mid].y)<0)l=x=mid;
				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)r=x=mid;
				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;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 95ms
memory: 73216kb

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: 96ms
memory: 73380kb

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: 73092kb

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: 6962ms
memory: 110076kb

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
616519241
614626805
...

result:

wrong answer 29th numbers differ - expected: '616568900', found: '616519241'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #19:

score: 0
Wrong Answer
time: 5799ms
memory: 107892kb

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: 0
Wrong Answer

Test #25:

score: 0
Wrong Answer
time: 6041ms
memory: 107988kb

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:

wrong answer 2442nd numbers differ - expected: '1', found: '0'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%