QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#618315#2559. Endless RoadOthersWA 3ms74836kbC++145.2kb2024-10-06 20:53:332024-10-06 20:53:34

Judging History

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

  • [2024-10-06 20:53:34]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:74836kb
  • [2024-10-06 20:53:33]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define wr(x,ch) write(x),putchar(ch)
using namespace std;
typedef pair<int,int> pai;
#define x first
#define y second
ll read() {
	ll x=0;bool f=0;char c=getchar();
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
void write(ll x) {
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10^48);
	return ;
}
const int N=5e5,inf=0x7f7f7f7f;
int flag[N],bit[N],top,n,lst[N],nxt[N];
set<int> st;
struct rg {
	int l,r,i;
	bool operator<(const rg &p) const {
		return r<p.r||(r==p.r&&(l>p.l||(l==p.l&&i<p.i)));
	}
}a[N];
struct node {
	int Maxl,tag;
	pai Minl,Mins;
	int Mr,Ml;
}tr[N<<2];
pai operator+(const pai &x,const pai &y) {
	if(x.x==y.x) return a[x.y].i<a[y.y].i?x:y;
	return min(x,y);
}
void update(int p,int t) {
	tr[p].Mins.x+=t;
	tr[p].tag+=t;
	return ;
}
void pushdown(int p) {
	if(tr[p].tag) update(p<<1,tr[p].tag),update(p<<1|1,tr[p].tag),tr[p].tag=0;
	return ;
}
void pushup(int p) {
	tr[p].Maxl=max(tr[p<<1].Maxl,tr[p<<1|1].Maxl);
	tr[p].Minl=tr[p<<1].Minl+tr[p<<1|1].Minl;
	tr[p].Mins=tr[p<<1].Mins+tr[p<<1|1].Mins;
	tr[p].Mr=max(tr[p<<1].Mr,tr[p<<1|1].Mr);
	tr[p].Ml=min(tr[p<<1].Ml,tr[p<<1|1].Ml);
	return ;
}
void build(int l,int r,int p,int lst) {
	if(l==r) {
		if(a[l].l>=lst) {
			tr[p].Mins=pai(flag[a[l].r]-flag[a[l].l],l);
			tr[p].Maxl=a[l].l;
			tr[p].Minl=pai(inf,0);
			tr[p].Mr=a[l].r-1;
			tr[p].Ml=a[l].l;
		}else {
			tr[p].Mins=pai(inf,0);
			tr[p].Minl=pai(a[l].l,l);
			tr[p].Maxl=0;
			tr[p].Mr=0;
			tr[p].Ml=inf;
		}
		return ;
	}
	int mid=l+r>>1;
	build(l,mid,p<<1,lst),build(mid+1,r,p<<1|1,max(lst,tr[p<<1].Maxl));
	return pushup(p);
}
void add(int x,int y) {
	while(x<=top) bit[x]+=y,x+=(x&-x);
	return ;
}
int ask(int x) {
	int tot=0;
	while(x) tot+=bit[x],x-=(x&-x);
	return tot;
}
int askl(int l,int r,int p,int lim) {
	if(tr[p].Mr<lim) return -1;
	if(l==r) return l;
	int mid=l+r>>1,ans;
	if((ans=askl(l,mid,p<<1,lim))!=-1) return ans;
	return askl(mid+1,r,p<<1|1,lim);
}
int askr(int l,int r,int p,int lim) {
	if(tr[p].Ml>lim) return -1;
	if(l==r) return l;
	int mid=l+r>>1,ans;
	if((ans=askr(mid+1,r,p<<1|1,lim))!=-1) return ans;
	return askr(l,mid,p<<1,lim);
}
void add(int s,int t,int l,int r,int p,int d) {
	if(s>t) return ;
	if(s<=l&&r<=t) return update(p,-d);
	int mid=l+r>>1;pushdown(p);
	if(s<=mid) add(s,t,l,mid,p<<1,d);
	if(t>mid) add(s,t,mid+1,r,p<<1|1,d);
	return pushup(p);
}
void deal(int x) {
	int l=askl(1,n,1,x),r=askr(1,n,1,x);
	add(l,r,1,n,1,flag[x+1]-flag[x]);
	add(x,flag[x+1]-flag[x]);
	return ;
}
int ask1(int s,int t,int l,int r,int p) {
	if(s>t) return 0;
	if(s<=l&&r<=t) return tr[p].Maxl;
	int mid=l+r>>1,ans=0;
	if(s<=mid) ans=max(ans,ask1(s,t,l,mid,p<<1));
	if(t>mid) ans=max(ans,ask1(s,t,mid+1,r,p<<1|1));
	return ans;
}
int ask3(int s,int t,int l,int r,int p) {
	if(s>t||!tr[p].Mins.y) return t+1;
	if(s<=l&&r<=t) {
		if(l==r) return l;
		int mid=l+r>>1,tmp=ask3(s,t,l,mid,p<<1);
		if(tmp!=t+1) return tmp;
		return ask3(s,t,mid+1,r,p<<1|1);
	}
	int mid=l+r>>1,tmp;
	if(s<=mid) {
		tmp=ask3(s,t,l,mid,p<<1);
		if(tmp!=t+1) return tmp;
	}
	return ask3(s,t,mid+1,r,p<<1|1);
}
pai ask2(int s,int t,int l,int r,int p) {
	if(s>t) return pai(inf,0);
	if(s<=l&&r<=t) return tr[p].Minl;
	int mid=l+r>>1;
	pai ans=pai(inf,0);
	if(s<=mid) ans=ans+ask2(s,t,l,mid,p<<1);
	if(t>mid) ans=ans+ask2(s,t,mid+1,r,p<<1|1);
	return ans;
}
void del(int x,int l,int r,int p) {
	if(l==r) {
		tr[p].Mins=pai(inf,0);
		tr[p].Minl=pai(inf,0);
		tr[p].tag=0;
		tr[p].Maxl=0;
		tr[p].Mr=0;
		tr[p].Ml=inf;
		return ;
	}
	int mid=l+r>>1;
	pushdown(p);
	if(x<=mid) del(x,l,mid,p<<1);
	else del(x,mid+1,r,p<<1|1);
	return pushup(p);
}
void add(int x,int l,int r,int p) {
	if(l==r) {
		tr[p].Maxl=0,tr[p].tag=0;
		tr[p].Minl=pai(inf,0),tr[p].Mins=pai(flag[a[x].r]-flag[a[x].l]-(ask(a[x].r-1)-ask(a[x].l-1)),x);
		tr[p].Mr=a[x].r-1,tr[p].Ml=a[x].l;
		return ;
	}
	int mid=l+r>>1;pushdown(p);
	if(x<=mid) add(x,l,mid,p<<1);
	else add(x,mid+1,r,p<<1|1);
	return pushup(p);
}
signed main() {
//	system("fc ex_ds1.out ds.out");
//	return 0;
//	freopen("ex_ds2.in","r",stdin);
//	freopen("ds.out","w",stdout);
//	freopen("ds.in","r",stdin);
//	freopen("ds.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++) a[i].l=read()+1,a[i].r=read()+1,flag[++top]=a[i].l,flag[++top]=a[i].r,a[i].i=i;
	sort(flag+1,flag+top+1),top=unique(flag+1,flag+top+1)-flag-1;
	for(int i=1;i<=n;i++) a[i].l=lower_bound(flag+1,flag+top+1,a[i].l)-flag,a[i].r=lower_bound(flag+1,flag+top+1,a[i].r)-flag;
	sort(a+1,a+n+1);
	build(1,n,1,0);
	for(int i=1;i<top;i++) st.insert(i),lst[i]=i-1,nxt[i]=i+1;
	nxt[0]=1,nxt[top-1]=0,lst[0]=top-1;
	for(int i=1;i<=n;i++) {
		int t=tr[1].Mins.y;
		if(tr[1].Mins.x) {
			for(int j=*st.lower_bound(a[t].l);j<a[t].r&&j;j=nxt[j]) 
				deal(j),lst[nxt[j]]=lst[j],nxt[lst[j]]=nxt[j];
			auto L=st.lower_bound(a[t].l),R=st.lower_bound(a[t].r);
			st.erase(L,R);
		}
		del(t,1,n,1);
		int ml=ask1(1,t-1,1,n,1),tlim=ask3(t+1,n,1,n,1);
		pai tmp;
		while((tmp=ask2(t+1,tlim-1,1,n,1)).y>=ml&&tmp.x!=inf) 
			add(tmp.y,1,n,1);
		wr(a[t].i,' ');
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
1 2
2 3
3 4
4 5
1 3
3 5

output:

1 2 5 3 4 6 

result:

ok 6 tokens

Test #2:

score: 0
Accepted
time: 3ms
memory: 74356kb

input:

4
3 7
10 14
1 6
6 11

output:

1 3 2 4 

result:

ok 4 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 73832kb

input:

100
50 51
49 51
49 52
48 52
48 53
47 53
47 54
46 54
46 55
45 55
45 56
44 56
44 57
43 57
43 58
42 58
42 59
41 59
41 60
40 60
40 61
39 61
39 62
38 62
38 63
37 63
37 64
36 64
36 65
35 65
35 66
34 66
34 67
33 67
33 68
32 68
32 69
31 69
31 70
30 70
30 71
29 71
29 72
28 72
28 73
27 73
27 74
26 74
26 75
25...

output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 

result:

ok 100 tokens

Test #4:

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

input:

100
41 42
99 100
47 48
50 51
56 57
61 62
27 28
85 86
44 45
3 4
26 27
20 21
92 93
33 34
86 87
69 70
84 85
62 63
81 82
2 3
13 14
32 33
82 83
70 71
46 47
45 46
19 20
83 84
57 59
63 65
59 61
82 84
45 47
48 50
70 72
42 44
84 86
26 28
61 63
2 4
17 19
65 67
54 56
67 69
96 99
42 45
47 50
34 37
14 17
51 54
7...

output:

1 2 3 4 5 6 8 13 15 16 17 18 19 23 24 28 7 9 14 22 25 26 29 30 31 34 35 42 43 44 10 11 12 21 27 32 36 37 38 39 45 50 51 55 63 20 33 40 41 47 48 52 54 46 69 65 83 92 74 84 85 78 76 98 95 66 89 77 58 73 57 91 100 96 79 99 60 71 61 72 82 90 62 59 67 86 68 81 93 53 49 80 70 56 64 75 87 88 94 97 

result:

wrong answer 7th words differ - expected: '7', found: '8'