Submission #51045723


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define md(a) a=(a%mod+mod)%mod
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)

/*
inline int qp(int a,int n){int b=1;while(n){if(n&1)b=b*a%mod;a=a*a%mod,n>>=1;}return b;}
struct BIT
{
	int c[N],upd;
	inline void init(int n){upd=n;for(int i=0;i<=upd;i++)c[i]=0;}
	inline void add(int x,int d){for(;x<=upd;x+=(x&-x))c[x]+=d;}
	inline int ask(int x){int w=0;for(;x;x-=(x&-x))w+=c[x];return w;}
}T;
struct Seg{int l,r,dat;}tree[N*4];
inline void pushup(int v){tree[v].dat=max(tree[v*2].dat,tree[v*2+1].dat);}
void build(int v,int l,int r)
{
	tree[v]={l,r,0};if(l==r)return ;
	int mid=(l+r)>>1;build(v*2,l,mid),build(v*2+1,mid+1,r);
}
void add(int v,int x,int d)
{
	if(tree[v].l==tree[v].r)return void(tree[v].dat=d);
	int mid=(tree[v].l+tree[v].r)>>1;add(v*2+(x>mid),x,d),pushup(v);
}
int ask(int v,int l,int r)
{
	if(l<=tree[v].l&&tree[v].r<=r)return tree[v].dat;int mid=(tree[v].l+tree[v].r)>>1,w=0;
	if(l<=mid)w=max(w,ask(v*2,l,r));if(r>mid)w=max(w,ask(v*2+1,l,r));return w;
}
*/
const int N=400005;
int n,a[N],Q;map<int,int>mp;
int nxt[N],pre[N];
signed main()
{
	scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=0;i<=n+1;i++)nxt[i]=i+1,pre[i]=i-1,mp[a[i]]=i;n++;
	int del=n;
	cin>>Q;
	while(Q--)
	{
		int op,x,y;scanf("%d%d",&op,&x);
		if(op==1)
		{
			scanf("%d",&y),n++,a[n]=y,mp[y]=n;y=n;
			int p=mp[x],q=nxt[p];nxt[p]=y,pre[y]=p,nxt[y]=q,pre[q]=y;
		}
		else
		{
			x=mp[x];int p=pre[x],q=nxt[x];
			nxt[p]=q,pre[q]=p;
		}
	}
	int now=0;
	while(1)
	{
		now=nxt[now];if(now==del)break;
		printf("%d ",a[now]);
	}
	return 0;
}

Submission Info

Submission Time
Task E - Insert or Erase
User Er1nyes
Language C++ 20 (gcc 12.2)
Score 475
Code Size 1705 Byte
Status AC
Exec Time 324 ms
Memory 27288 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:40:9: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
   40 |         for(int i=0;i<=n+1;i++)nxt[i]=i+1,pre[i]=i-1,mp[a[i]]=i;n++;
      |         ^~~
Main.cpp:40:65: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
   40 |         for(int i=0;i<=n+1;i++)nxt[i]=i+1,pre[i]=i-1,mp[a[i]]=i;n++;
      |                                                                 ^
Main.cpp:39:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~
Main.cpp:39:50: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);
      |                                             ~~~~~^~~~~~~~~~~~
Main.cpp:45:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |                 int op,x,y;scanf("%d%d",&op,&x);
      |                            ~~~~~^~~~~~~~~~~~~~~
Main.cpp:48:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |                         scanf("%d",&y),n++,a[n]=y,mp[y]=n;y=n;
      |                         ~~~~~^~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 2
AC × 24
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
min.txt AC 1 ms 3680 KiB
random_01.txt AC 324 ms 27104 KiB
random_02.txt AC 212 ms 18752 KiB
random_03.txt AC 224 ms 21916 KiB
random_04.txt AC 80 ms 10176 KiB
random_05.txt AC 260 ms 21284 KiB
random_06.txt AC 159 ms 14316 KiB
random_07.txt AC 217 ms 20128 KiB
random_08.txt AC 86 ms 11340 KiB
random_09.txt AC 171 ms 15976 KiB
random_10.txt AC 113 ms 11968 KiB
random_11.txt AC 156 ms 16072 KiB
random_12.txt AC 30 ms 6068 KiB
random_13.txt AC 258 ms 27044 KiB
random_14.txt AC 201 ms 21392 KiB
random_15.txt AC 159 ms 15968 KiB
random_16.txt AC 262 ms 27080 KiB
random_17.txt AC 202 ms 21328 KiB
random_18.txt AC 157 ms 16176 KiB
random_19.txt AC 83 ms 15612 KiB
random_20.txt AC 150 ms 27288 KiB
random_21.txt AC 78 ms 15488 KiB
sample_01.txt AC 1 ms 3656 KiB
sample_02.txt AC 1 ms 3756 KiB