QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#547679#7072. Photographucup-team3474RE 0ms0kbC++203.3kb2024-09-05 01:52:422024-09-05 01:52:42

Judging History

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

  • [2024-09-05 01:52:42]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-05 01:52:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1919810,inf=0x3f3f3f3f;
typedef long long ll;
typedef pair<ll,ll> PII;
#define int long long
ll n,m,k;
ll a[N],b[N];
char s[N];
ll c[N];

int lst[N],ne[N];

typedef struct{
	int l,r;
	int mx,mn;
	int tag1,tag2;
}Node;

Node tr[N];


// void pushup(int u){
// 	tr[u].mx=max(tr[u<<1].mx,tr[u<<1|1].mx);
// }

void pushdown(int u){
	if(tr[u].tag1!=0){
		if(tr[u<<1].l==tr[u<<1].r) tr[u<<1].mx=max(tr[u<<1].mx,tr[u].tag1);
		if(tr[u<<1|1].l==tr[u<<1|1].r) tr[u<<1|1].mx=max(tr[u<<1|1].mx,tr[u].tag1);
		tr[u<<1].tag1=max(tr[u<<1].tag1,tr[u].tag1);
		tr[u<<1|1].tag1=max(tr[u<<1|1].tag1,tr[u].tag1);
		tr[u].tag1=0;
	}
	if(tr[u].tag2!=inf){
		if(tr[u<<1].l==tr[u<<1].r) tr[u<<1].mn=min(tr[u<<1].mn,tr[u].tag2);
		if(tr[u<<1|1].l==tr[u<<1|1].r) tr[u<<1|1].mn=min(tr[u<<1|1].mn,tr[u].tag2);
		tr[u<<1].tag2=min(tr[u<<1].tag2,tr[u].tag2);
		tr[u<<1|1].tag2=min(tr[u<<1|1].tag2,tr[u].tag2);
		tr[u].tag2=inf;
	}
}

void build(int u,int l,int r){
	tr[u]={l,r,0,inf,0,inf};
	if(l==r){
		// tr[u].lst=
		return;
	}else{
		int mid=l+r>>1;
		build(u<<1,l,mid);
		build(u<<1|1,mid+1,r);
		// pushup(u);
	}
}


void modify(int u,int l,int r,int c,int type){
	// cout<<u<<" "<<tr[u].l<<" "<<tr[u].r<<" "<<l<<" "<<r<<endl;
	if(l>r) return;
	if(tr[u].l>=l&&tr[u].r<=r){
		if(type==1){
			if(tr[u].l==tr[u].r) tr[u].mx=max(tr[u].mx,c);
			tr[u].tag1=max(tr[u].tag1,c);
		}
		if(type==2){
			if(tr[u].l==tr[u].r) tr[u].mn=min(tr[u].mn,c);
			tr[u].tag2=min(tr[u].tag2,c);
		}
		
		
	}else{
		pushdown(u);
		int mid=tr[u].l+tr[u].r>>1;
		if(l<=mid) modify(u<<1,l,r,c,type);
		if(r>mid) modify(u<<1|1,l,r,c,type);
		// pushup(u);
	}
}


Node query(int u,int l){
	if(tr[u].l==tr[u].r){
		return tr[u];
	}else{
		pushdown(u);
		int mid=tr[u].l+tr[u].r>>1;
		if(l<=mid) return query(u<<1,l);
		else return query(u<<1|1,l);
	}
}

void __(){
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++){
		a[i+n]=a[i];
		b[i+n]=b[i];
	}
	for(int i=1;i<=n;i++) c[i]=b[i];
	int id=1;
//	m--;
	do{
		// build(1,1,n);
		set<int> se;
		ll now=0;
		ll ans=0;
		for(int i=id,j=1;j<=n;j++,i++){
			// cout<<a[i]<<" ";
			// Node nd=query(1,a[i]);
			// cout<<114514<<endl;
			int lst=0,ne=inf;
			auto it=se.lower_bound(a[i]);
			if(it!=se.begin()){
				auto it1=it;
				it1--;
				lst=*it1;
			}
			if(it!=se.end()){
				auto it1=it;
				it1++;
				if(it1!=se.end())
				ne=*it1;
			}
			// cout<<lst<<" "<<ne<<endl;
			ll res=0;
			if(lst!=0&&ne!=inf){
				res=-(c[lst]-c[ne])*(c[lst]-c[ne]);
			}
			// cout<<res<<" ";
			if(lst!=0){
				res+=(c[a[i]]-c[lst])*(c[a[i]]-c[lst]);
			}
			// cout<<res<<" ";
			if(ne!=inf){
				res+=(c[a[i]]-c[ne])*(c[a[i]]-c[ne]);
			}
			// cout<<res<<" ";
			// cout<<lst<<" "<<ne<<endl;
			modify(1,a[i]+1,n,a[i],1);
			modify(1,1,a[i]-1,a[i],2);
			now+=res;
			ans+=now;
			// cout<<ans<<endl;
		}
		// cout<<endl;
		printf("%lld\n",ans);
		if(m==0) break;
		int x;
		scanf("%lld",&x);
		ll move=(ans+x)%n;
		// cout<<move<<endl;
		// id=(id+move+1)%n+1;
		for(int j=1;j<=move;j++) id=id%n+1;
	}while(m--);
}


signed main(){
	int _=1;
	// cin>>_;
	while(_--){
		__();
	}
}

详细

Test #1:

score: 0
Runtime Error

input:

5 4
1 2 3 4 5
1 2 3 4 5
6
6
8
10

output:


result: