Submission #916941

# Submission time Handle Problem Language Result Execution time Memory
916941 2024-01-26T20:05:40 Z MilosMilutinovic Sweeping (JOI20_sweeping) C++14
0 / 100
18000 ms 35096 KB
#include<bits/stdc++.h>
 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
 
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
 
ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
 
int n,m,q;
int v[1500005][2],fa[1500005],ch[1500005][2],tag[1500005][2],prior[1500005];
mt19937 rng(time(0));
 
void make(int id){ tag[id][0]=tag[id][1]=-1; prior[id]=rng(); fa[id]=ch[id][0]=ch[id][1]=0; }
 
void pushdown(int id){
  	assert(id>=0);
	if(!id) return;
	for(int i=0;i<2;i++){
		if(tag[id][i]==-1) continue;
		for(int j=0;j<2;j++){
			if(ch[id][j]==0) continue;
			v[ch[id][j]][i]=tag[id][i];
			tag[ch[id][j]][i]=tag[id][i];
		}
		tag[id][i]=-1;
	}
}
 
void split(int id,int&l,int&r,int a,int b,int idx){
	//printf("%d %d %d\n",id,l,r);
	//fflush(stdout);
  	assert(id>=0);
	if(!id) return (void)(l=r=0);
	pushdown(id);
	if(v[id][0]<=a&&v[id][1]<=b&&(mp(v[id][0],v[id][1])!=mp(a,b)||id<idx)){
		fa[ch[id][1]]=0;
		split(ch[id][1],ch[id][1],r,a,b,idx);
		l=id; 
		fa[ch[id][1]]=id;
	}else{
		fa[ch[id][0]]=0;
		split(ch[id][0],l,ch[id][0],a,b,idx);
		r=id;  
		fa[ch[id][0]]=id;
	}
}
 
void merge(int&id,int l,int r){
	//printf("%d %d %d\n",id,l,r);
	//fflush(stdout);
  	assert(id>=0&&l>=0&&r>=0);
	if(!l) return (void)(id=r);
	if(!r) return (void)(id=l);
	pushdown(l);
	pushdown(r);
	if(prior[l]>prior[r]) swap(l,r);
	int L=0,R=0;
	split(l,L,R,v[r][0],v[r][1],r);
	fa[ch[r][0]]=0;
	fa[ch[r][1]]=0;
	merge(ch[r][0],ch[r][0],L);
	merge(ch[r][1],ch[r][1],R);
	fa[ch[r][0]]=r;
	fa[ch[r][1]]=r;
	id=r;
	pushdown(id);
}
 
int main(){
	n=readint();
	m=readint();
	q=readint();
	for(int i=1;i<=m;i++) for(int j=0;j<2;j++) v[i][j]=readint();
	for(int i=1;i<=m;i++) make(i);
	while(q--){
		int t=readint();
		if(t==1){
			int i=readint();
			vector<int> anc;
			for(int v=i;v;v=fa[v]) assert(anc.size()<=n),anc.pb(v);
			reverse(anc.begin(),anc.end());
			for(int v:anc) pushdown(v);
			printf("%d %d\n",v[i][0],v[i][1]);
		}
		if(t==2){
			int l=readint();
			int root=0;
			vector<int> ids;
			for(int i=1;i<=m;i++) if(!fa[i]) ids.pb(i);
			for(int i:ids){
				int L=0,R=0;
				split(i,L,R,n-l,l,1e9);
				v[L][0]=n-l;
				tag[L][0]=n-l;
				pushdown(L);
				pushdown(R);
				merge(root,root,L);
				pushdown(root);
			}
		}
		if(t==3){
			int l=readint();
			int root=0;
			vector<int> ids;
			for(int i=1;i<=m;i++) if(!fa[i]) ids.pb(i);
			for(int i:ids){
				int L=0,R=0;
				split(i,L,R,l,n-l,1e9);
				v[L][1]=n-l;
				tag[L][1]=n-l;
				pushdown(L);
				pushdown(R);
				merge(root,root,L);
				pushdown(root);
			}
		}
		if(t==4){
			make(++m);
			for(int j=0;j<2;j++) v[m][j]=readint();
		}
	}
	return 0;
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from sweeping.cpp:1:
sweeping.cpp: In function 'int main()':
sweeping.cpp:97:44: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   97 |    for(int v=i;v;v=fa[v]) assert(anc.size()<=n),anc.pb(v);
      |                                  ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 25 ms 8796 KB Output is correct
2 Correct 13 ms 8536 KB Output is correct
3 Correct 3 ms 8540 KB Output is correct
4 Correct 20 ms 9024 KB Output is correct
5 Correct 51 ms 8536 KB Output is correct
6 Runtime error 10 ms 17240 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 18005 ms 35096 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 18037 ms 34912 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 18037 ms 34912 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 8796 KB Output is correct
2 Correct 13 ms 8536 KB Output is correct
3 Correct 3 ms 8540 KB Output is correct
4 Correct 20 ms 9024 KB Output is correct
5 Correct 51 ms 8536 KB Output is correct
6 Runtime error 10 ms 17240 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -