QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#461785#8817. Fast Median TransformCrysflyWA 101ms57572kbC++173.2kb2024-07-03 01:51:522024-07-03 01:51:52

Judging History

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

  • [2024-07-03 01:51:52]
  • 评测
  • 测评结果:WA
  • 用时:101ms
  • 内存:57572kb
  • [2024-07-03 01:51:52]
  • 提交

answer

// what is matter? never mind. 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#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 ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
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 1000005
#define inf 0x3f3f3f3f

int n,m,q,res;
int a[maxn],b[maxn],top[maxn];

struct node{
	int l,r;
	node(int x=0,int y=0){l=x,r=y;}
	bool emp(){return l>r;}
	bool in(int x){return l<=x && x<=r;}
	int val(int x){return max(l,min(x,r));}
	void swp(){if(l>r)swap(l,r);}
};
node operator +(node a,node b){
	return node(max(a.l,b.l),min(a.r,b.r));
}

node tr[maxn<<2],tmp[maxn];
void up(int p){
	tr[p]=tr[p<<1]+tr[p<<1|1];
}
void build(int p,int l,int r){
	if(l==r) return tr[p]=tmp[l],void();
	int mid=l+r>>1;
	build(p<<1,l,mid);
	build(p<<1|1,mid+1,r); up(p);
}
void mdf(int p,int l,int r,int x){
	if(l==r) return tr[p]=tmp[l],void();
	int mid=l+r>>1;
	x<=mid?mdf(p<<1,l,mid,x):mdf(p<<1|1,mid+1,r,x); up(p);
}

int bound(int p,int l,int r,node t=node(0,1<<29)){
	if(l==r)return t.val(tmp[l].l);
	int mid=l+r>>1;
	if((t+tr[p<<1|1]).emp()) return bound(p<<1|1,mid+1,r,t);
	return bound(p<<1,l,mid,t+tr[p<<1|1]);
}

int t[maxn],len;
int fa[maxn];
int idb[maxn];
int gf(int x){
	while(x!=fa[x])x=fa[x]=fa[fa[x]];
	return x;
}

int col[maxn];
void update(int x,int y){
	a[x]=y;
	int p=((x-n)%m+m)%m;
	tmp[x]=node(a[x],b[p]),tmp[x].swp();
	mdf(1,0,n-1,x);
}

int ask(int x){
	if(tr[1].emp()) return bound(1,0,n-1);
	
	auto chk=[&](int k,int p)->bool{
		if(k<tr[1].l)return 0;
		if(k>tr[1].r)return 1;
	//	int p=upper_bound(t+1,t+len+1,k)-t-1;
	//	cout<<"chk "<<k<<" "<<p<<"\n";
		if(col[p]==-1) return x<=k;
		int pos=col[p];
		return a[pos]<=k;
	};
	
	int l=1,r=len;
	while(l<r){
		int mid=l+r>>1;
		if(chk(t[mid],mid))r=mid;
		else l=mid+1;
	}
	
	int pos=max(0,l-1);
	l=t[pos],r=t[pos+1]-1;
	while(l<=r){
		int mid=l+r>>1;
		if(chk(mid,pos))r=mid;
		else l=mid+1;
	}
	return l;
}

signed main()
{
	n=read(),m=read(),q=read();
	For(i,0,n-1)a[i]=read();
	For(i,0,m-1)b[i]=read();
	
	Rep(i,n-1,0){
		int x=((i-n)%m+m)%m;
		tmp[i]=node(a[i],b[x]),tmp[i].swp();
	}
	build(1,0,n-1);
	
	For(i,0,m-1)t[++len]=b[i];
	sort(t+1,t+len+1),len=unique(t+1,t+len+1)-t-1;
	For(i,0,m-1) idb[i]=lower_bound(t+1,t+len+1,b[i])-t;
	
	For(i,0,len+1) fa[i]=i,col[i]=-1;
	Rep(i,n-1,min(0,n-1-m*2)){
		int x=((i-n)%m+m)%m;
		int y=((x-n)%m+m)%m;
		int is=(i%n+n)%n;
		x=idb[x],y=idb[y];
		if(x>y)swap(x,y);
		for(x=gf(x);x<y;x=gf(x)) fa[x]=x+1,col[x]=is;
	}
	
	For(_,1,q){
		int x=read(),y=read()^res,x0=read()^res;
		update(x,y);
		printf("%d\n",res=ask(x0));
	}
	return 0;
}
/*
2 3 1
1 3
4 2 3
0 1 2
*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 52980kb

input:

2 3 1
1 3
4 2 3
0 1 2

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 30ms
memory: 51716kb

input:

7544 46342 61280
502503176 235533984 25807599 157972679 165515044 49900751 319263394 415001783 484118278 66338951 101379665 401811486 99560840 428940529 446954335 441298416 199594033 401990145 466226082 46197720 182530354 363960963 347681314 119666637 46690647 410053668 39407033 170030166 10922704 1...

output:

310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
310583593
...

result:

ok 61280 numbers

Test #3:

score: 0
Accepted
time: 100ms
memory: 53564kb

input:

276482 77760 252326
160651556 103933544 346737062 211964399 15137989 491554726 347291202 30213116 47254058 362201158 48002518 60382110 266509839 255606564 472122834 361682117 247943170 535663355 414013024 349259137 218729809 355045528 433220305 251311253 536811863 466845786 416651881 523120703 19883...

output:

334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
334500963
...

result:

ok 252326 numbers

Test #4:

score: 0
Accepted
time: 101ms
memory: 57572kb

input:

179865 55334 268651
115683489 325871123 1541209 86153306 442086925 476969860 209328878 223499675 473804855 328627246 247579320 154078291 437053067 128960315 415053788 174497870 98614963 412108751 69213469 276622357 147405807 272638302 425562267 22785654 32972528 226050569 149140594 212382692 9350697...

output:

254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
254672346
...

result:

ok 268651 numbers

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 53108kb

input:

1 1 10
415578357
107299684
0 201845821 29711020
0 479396829 519527208
0 405565111 414423478
0 171856726 51568382
0 511415556 344498835
0 130878639 414853820
0 281382137 11801437
0 194491375 276814998
0 281070022 81190010
0 376264595 62365237

output:

107299684
107299684
107299684
107299684
107299684
107299684
107299684
107299684
107299684
107299684

result:

wrong answer 2nd numbers differ - expected: '412227660', found: '107299684'