QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#327608#8016. 不休陀螺zsq1472583690 1054ms237288kbC++141.9kb2024-02-15 11:23:022024-02-15 11:23:03

Judging History

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

  • [2024-02-15 11:23:03]
  • 评测
  • 测评结果:0
  • 用时:1054ms
  • 内存:237288kb
  • [2024-02-15 11:23:02]
  • 提交

answer

#pragma GCC optimize("Ofast","inline")
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e6+50;

void read(int&x)
{
	char c;
	while(c=getchar(),c<'0'||c>'9');x=c-'0';
	while(c=getchar(),c>='0'&&c<='9')x=x*10+c-'0';
}

int n,E,a[N],b[N],p[N],ro[N],st[N],top,fir[N],ans,w[N],f[N],t[N],tot,g[N],h[N];

bool cmp(int a,int b)
{
	return f[a]==f[b]?a<b:f[a]<f[b];
}

int find(int x)
{
	return x==ro[x]?x:(ro[x]=find(ro[x]));
}

int val(int x)
{
	return E-p[find(x)]+fir[x-1];
}

int tl[N<<2],tr[N<<2],sum[N];

#define ls tl[x]
#define rs tr[x]
#define mid ((l+r)>>1)
#define LS ls,l,mid
#define RS rs,mid+1,r

void insert(int&x,int l,int r,int d)
{
	if(!x)x=++tot;++sum[x];
	if(l==r)return;
	if(d<=mid)insert(LS,d);
	else insert(RS,d);
}

int find(int x,int l,int r,int d)
{
	if(!x)return 0;
	if(d>=r)return sum[x];
	if(d<=mid)return find(LS,d);
	return find(LS,d)+find(RS,d);
}

void insert(int x,int val)
{
	for(int i=x;i<=n;i+=(i&(-i)))insert(t[i],1,n+1,val);
}

int find(int x,int val)
{
	int ans=0;
	for(int i=x;i;i-=(i&(-i)))ans+=find(t[i],1,n+1,val);
	return ans;
}

main()
{
//	freopen("in.txt","r",stdin);
//	freopen("top.in","r",stdin);
//	freopen("top.out","w",stdout);
	read(n);read(E);
	for(int i=1;i<=n;i++)read(a[i]),ro[i]=t[i]=g[i]=i;tot=n;
	for(int i=1;i<=n;i++)read(b[i]),fir[i]=fir[i-1]+(w[i]=max(0ll,a[i]-b[i])),p[i]=a[i]-w[i],f[i]=f[i-1]+b[i]-a[i];
	sort(g,g+1+n,cmp);
	for(int i=1;i<=n;i++)h[g[i]]=i+1;
	st[++top]=1;insert(n,0);ans+=b[1]>=a[1];
	for(int i=2;i<=n;i++)
	{
		while(top&&p[st[top]]<=p[i])ro[st[top--]]=i;
		st[++top]=i;
		int l=1,r=i-1,t=i+1;
		while(l<=r)
		{
			int pos=(l+r)>>1;
			if(fir[i]<=val(pos))t=pos,r=pos-1;
			else l=pos+1;
		}
		insert(n-i+1,h[i-1]);ans+=find(n-t+1,h[i]);
//		cout<<i<<' '<<t<<' '<<find(1)<<' '<<ans<<'\n';
	}
	cout<<ans;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 24684kb

input:

5000 939255322
47952340 92329911 61615795 40122788 47258178 29326499 9822850 42767362 86610596 60318756 52429688 87502511 50194916 96377063 74322128 19511341 28794957 53813791 79075058 35555414 5249682 45174421 101856091 25257909 94697470 45853817 82945426 108415825 41731145 87133877 75167193 598696...

output:

1846969

result:

wrong answer 1st lines differ - expected: '1846283', found: '1846969'

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 1054ms
memory: 225012kb

input:

774484 763692678
47702350 34856775 28447988 4178162 45063720 8232662 36845607 27038945 44858289 5952529 39159657 21628528 60199611 5544054 59216841 39287087 43449994 20034684 56440004 11583811 44465341 32347476 49196492 22731571 9481143 11726859 35167370 23103544 23109378 38822668 29778048 58004104 ...

output:

120877795985466

result:

wrong answer 1st lines differ - expected: '124023429', found: '120877795985466'

Subtask #3:

score: 0
Wrong Answer

Test #10:

score: 0
Wrong Answer
time: 806ms
memory: 237288kb

input:

1000000 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

137320529452716

result:

wrong answer 1st lines differ - expected: '99999500000', found: '137320529452716'

Subtask #4:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 150ms
memory: 135892kb

input:

174457 888
0 0 0 0 1 0 0 1 1 1 0 1 0 1 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 0 1 0 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 1...

output:

5107979669467

result:

wrong answer 1st lines differ - expected: '329807918', found: '5107979669467'

Subtask #5:

score: 0
Wrong Answer

Test #18:

score: 0
Wrong Answer
time: 495ms
memory: 191376kb

input:

343922 773619774
0 8292680 5684115 0 0 170056 5385926 0 0 1588575 0 0 10947891 170867 35145 0 0 103085 7231562 0 0 0 0 11128944 0 4872226 0 2879880 7565181 0 8631665 0 5162564 9511835 514165 0 9628987 14357934 174784 0 12400154 0 0 8198218 0 8496060 0 0 0 0 10376826 3523227 0 14548249 0 6840016 0 0 ...

output:

15309513917493

result:

wrong answer 1st lines differ - expected: '36107528', found: '15309513917493'

Subtask #6:

score: 0
Wrong Answer

Test #24:

score: 0
Wrong Answer
time: 568ms
memory: 198000kb

input:

468676 582048177
6889433 7293342 20676061 15545414 4911497 12352219 8921719 1705801 19695926 25259227 2645394 17518171 19753552 9449377 982708 22479531 1267985 15594372 20685422 9627290 2017543 6459134 18614020 16206301 14962487 12932255 7101003 29140540 6479702 20607124 2540287 15565156 20274141 11...

output:

34666787836873

result:

wrong answer 1st lines differ - expected: '353280708', found: '34666787836873'