QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#751984#9570. Binary Treehuang123zsWA 1ms8036kbC++141.4kb2024-11-15 21:28:592024-11-15 21:29:01

Judging History

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

  • [2024-11-15 21:29:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:8036kb
  • [2024-11-15 21:28:59]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=3.1e5,SN=570;
inline LL read(){
	LL x=0,ff=1;
	char c=getchar();
	while(!isdigit(c)&&c!='-') c=getchar();
	if(c=='-') c=getchar(),ff=-1;
	while(isdigit(c)) x=x*10ll+c-'0',c=getchar();
	return x*ff;
}
int n,B;
int pos[N];
struct node{
	int x,op,idd;
}t[N];
struct Block{
	LL dp[SN*2];
	int res[SN*2];
	void build(int T,int l,int r){
		int len=r-l+1;
		for(int i=-len;i<=len;++i)
			dp[i+SN]=0,res[i+SN]=i;
		for(int i=l;i<=r;++i){
			if(t[i].idd>T) continue;
			for(int j=-len;j<=len;++j){
				if(t[i].op==1){
					if(res[j+SN]<0)
						dp[j+SN]=dp[j+SN]+t[i].x;
					res[j+SN]++;
				}
				else{
					if(res[j+SN]>0)
						dp[j+SN]=dp[j+SN]+t[i].x;
					res[j+SN]--;
				}
			} 
		}
	}
}T[SN];
bool cmp(const node& sa,const node& sb){
	return sa.x<sb.x;
}
int idd(int x){
	return (x-1)/B+1;
}
int main(){
	int casecnt=1;
	while(casecnt--){
		n=read();
		B=sqrt(n);
		for(int i=1;i<=n;++i){
			t[i].op=read()-1,t[i].x=read();
			t[i].idd=i;
		}
		sort(t+1,t+n+1,cmp);
		for(int i=1;i<=n;++i)
			pos[t[i].idd]=i;
		for(int i=1;i<=n;++i){
			int w=idd(pos[i]);
			T[w].build(i,(w-1)*B+1,min(w*B,n));
			int now=0;
			LL ans=0;
			for(int i=1;i<=idd(n);++i){
				int y=max(-B,min(B,now));
				ans+=T[i].dp[B+SN];
				now=T[i].res[B+SN]+now-y;
			}
			printf("%lld\n",ans);
		}
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 8036kb

input:

2
5
0 0
1 5
2 4
0 0
0 0

output:

0
1

result:

wrong answer Token parameter [name=op] equals to "0", doesn't correspond to pattern "[?!]{1,1}" (test case 1)