QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#577798#964. Excluded MinciuimRE 8ms42936kbC++144.2kb2024-09-20 14:50:502024-09-20 14:50:50

Judging History

This is the latest submission verdict.

  • [2024-09-20 14:50:50]
  • Judged
  • Verdict: RE
  • Time: 8ms
  • Memory: 42936kb
  • [2024-09-20 14:50:50]
  • Submitted

answer

bool M1;
#define look_memory cerr<<abs(&M2-&M1)/1024.0/1024<<" MB\n"
#define look_time cerr<<(clock()-Time)*1.0/CLOCKS_PER_SEC<<'\n'
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstring>
#include <array>
#include <algorithm>
#include <queue>
#include <vector>
#include <bitset>
#include <ctime>
#include <cstdlib>
#include <random>
#include <set>
#include <ctime>
#include <map>
#include <stack>
#include <unordered_map>
#include <assert.h>
#define i128 __int128
#define ll long long
#define uint unsigned
#define ull unsigned long long
#define fo(a,b,c) for(ll a=b;a<=c;++a)
#define re(a,b,c) for(ll a=b;a>=c;--a)
#define pii pair<ll,ll>
#define pdd pair<db,db>
#define fi first
#define pb push_back
#define se second
#define ite set<pii> ::iterator
using namespace std;
const ll mod=998244353;
inline ll gi()
{
	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<<1) + (x<<3) + (ch^48);
		ch = getchar();
	}
	return x * f;
}
ll _=1;
const ll inf=2e17+5,iinf=2e9;
const ll N=500005;
struct sgt
{
	pii mx[N];
	ll tag[N];
	void wk(ll rt,ll val)
	{
		tag[rt]+=val;
		mx[rt].fi+=val;
	}
	void pd(ll rt)
	{
		if(tag[rt]==0) return;
		wk(rt*2,tag[rt]);
		wk(rt*2+1,tag[rt]);
		tag[rt]=0;
	}
	void bt(ll rt,ll l,ll r,ll tg)
	{
		if(l==r)
		{
			if(tg) mx[rt]={-inf,-l};
			else mx[rt]={-inf,l};
			return;
		}
		ll mid=(l+r)/2;
		bt(rt*2,l,mid,tg);
		bt(rt*2+1,mid+1,r,tg);
		mx[rt]=max(mx[rt*2],mx[rt*2+1]);
	}
	void ud(ll rt,ll l,ll r,ll L,ll R,ll val)
	{
		if(L<=l&&r<=R)
		{
			wk(rt,val);
			return;
		}
		pd(rt);
		ll mid=(l+r)/2;
		if(L<=mid) ud(rt*2,l,mid,L,R,val);
		if(R>mid) ud(rt*2+1,mid+1,r,L,R,val);
		mx[rt]=max(mx[rt*2],mx[rt*2+1]);
	}
	void cg(ll rt,ll l,ll r,ll pos,pii val)
	{
		if(l==r)
		{
			mx[rt]=val;
			return;
		}
		pd(rt);
		ll mid=(l+r)/2;
		if(pos<=mid) cg(rt*2,l,mid,pos,val);
		else cg(rt*2+1,mid+1,r,pos,val);
		mx[rt]=max(mx[rt*2],mx[rt*2+1]);
	}
	pii qr(ll rt,ll l,ll r,ll L,ll R)
	{
		if(L<=l&&r<=R) return mx[rt];
		pd(rt);
		ll mid=(l+r)/2;
		if(R<=mid) return qr(rt*2,l,mid,L,R);
		if(L>mid) return qr(rt*2+1,mid+1,r,L,R);
		return max(qr(rt*2,l,mid,L,R),qr(rt*2+1,mid+1,r,L,R));
	}
}t1,t2;
ll n,q;
ll a[N];
struct IO
{
	ll l,r,id;
}e[N];
bool cmp(IO za,IO zb)
{
	if(za.l==zb.l) return za.r>zb.r;
	return za.l<zb.l;
}
vector<ll> g[N];
ll bit[N];
ll lb(ll x)
{
	return x&-x;
}
void add(ll x,ll y)
{
	for(;x<=n;x+=lb(x)) bit[x]+=y;
}
ll qr(ll x)
{
	ll res=0;
	for(;x;x-=lb(x)) res+=bit[x];
	return res;
}
set<pii> sl,sr;
void ins(ll x)
{
	t1.cg(1,1,q,x,{qr(e[x].r)-qr(e[x].l-1),x});
	sl.insert({e[x].l,x});
	sr.insert({e[x].r,x});
}
void del(ll x)
{
	t1.cg(1,1,q,x,{-inf,x});
	sl.erase({e[x].l,x});
	ite it=sl.lower_bound({e[x].l,x});
	ll nxt=q;
	if(it!=sl.end()) nxt=it->se;
	sr.erase({e[x].r,x});
	it=sr.lower_bound({e[x].r,x});
	ll lim=0;
	if(it!=sr.begin())
	{
		it--;
		lim=it->fi;
	}
	
	while(1)
	{
		pii p=t2.qr(1,1,q,x,nxt);
		if(p.fi<=lim)break;
		ll zid=-p.se;
		nxt=zid;
		ins(zid);
		t2.cg(1,1,q,zid,{-inf,-zid});
	}
}
ll ans[N];
void sol()
{
	n=gi(),q=gi();
	fo(i,1,n) a[i]=gi();
	fo(i,1,n)
	{
		a[i]=min(a[i],n);
		g[a[i]].pb(i);
		add(i,1);
	}
	fo(i,1,q)
	{
		e[i].l=gi(),e[i].r=gi();
		e[i].id=i;
	}
	sort(e+1,e+1+q,cmp);
	t1.bt(1,1,q,0);
	t2.bt(1,1,q,1);
	ll zmx=0;
	fo(i,1,q)
	{
		if(zmx<e[i].r) ins(i);
		else
		{
			t2.cg(1,1,q,i,{e[i].r,-i});
		}
		zmx=max(zmx,e[i].r);
	}
	re(i,n,0)
	{
		for(ll x:g[i])
		{
			add(x,-1);
			if(sl.size())
			{
				ite it2=sl.lower_bound({x,inf}),it1=sr.lower_bound({x,-inf});
				if(it1!=sr.end()&&it2!=sl.begin())
				{
					it2--;
					t1.ud(1,1,q,it1->se,it2->se,-1);
				}
			}
		}
		while(1)
		{
			if(t1.mx[1].fi>=i)
			{
				ans[e[t1.mx[1].se].id]=i;
				del(t1.mx[1].se);
			}
			else break;
		}
	}
	fo(i,1,q) cout<<ans[i]<<'\n';
}
bool M2;
int main()
{
	int Time=clock();
	look_memory;
//	_=gi();
	while(_--)
	{
		sol();
		printf("\n");
	}
	look_time;
	return 0;
}

详细

Test #1:

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

input:

3 3
0 0 2
1 3
2 3
3 3

output:

3
1
0


result:

ok 3 number(s): "3 1 0"

Test #2:

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

input:

3 2
1 2 2
1 2
1 3

output:

0
3


result:

ok 2 number(s): "0 3"

Test #3:

score: 0
Accepted
time: 8ms
memory: 42936kb

input:

10 10
3 0 3 3 9 7 9 6 0 7
3 3
9 9
4 6
1 9
3 4
2 4
7 10
3 7
5 7
2 7

output:

0
1
0
5
0
1
1
0
0
1


result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 4ms
memory: 38856kb

input:

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

output:

1
0
2
7
1
4
0
2
8
3


result:

ok 10 numbers

Test #5:

score: 0
Accepted
time: 4ms
memory: 40880kb

input:

100 100
15 82 7 39 63 55 64 99 71 63 32 99 67 94 3 43 15 75 45 55 53 4 35 36 15 40 82 20 62 43 6 83 27 95 27 45 98 44 35 98 39 7 17 32 76 7 40 16 40 63 13 8 22 27 11 12 61 14 19 45 100 97 90 88 22 59 25 63 4 25 65 16 22 92 84 44 99 66 89 26 93 97 35 97 92 1 32 40 97 97 78 43 7 12 23 53 61 74 33 90
1...

output:

68
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
48
0
0
0
0
0
0
0
0
0
0
0
0
0
28
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0


result:

ok 100 numbers

Test #6:

score: 0
Accepted
time: 4ms
memory: 42744kb

input:

100 100
17 86 33 8 11 27 8 11 13 9 3 43 11 23 26 42 44 12 44 12 15 0 75 51 72 5 49 2 40 57 24 47 39 42 4 5 6 52 3 2 42 19 62 33 24 22 16 69 4 33 44 70 29 11 2 2 58 9 6 10 25 10 33 26 17 3 14 0 48 7 48 51 0 39 54 37 14 9 3 85 18 4 25 9 2 0 39 8 17 13 25 45 10 39 12 18 9 5 66 6
13 89
10 90
42 67
43 52...

output:

76
80
0
0
18
1
18
1
5
5
1
1
22
11
0
15
0
59
5
56
1
80
0
1
1
21
0
61
22
11
0
3
8
15
40
1
8
81
71
20
2
0
60
0
60
31
0
59
0
0
0
28
0
21
1
7
5
0
31
0
76
28
0
0
27
1
23
0
1
27
1
0
0
1
0
5
63
52
2
43
73
1
86
0
61
0
27
2
30
5
31
1
0
14
59
27
1
1
67
63


result:

ok 100 numbers

Test #7:

score: 0
Accepted
time: 4ms
memory: 42936kb

input:

100 100
6 1 1 5 13 11 35 5 3 2 0 4 0 9 1 2 3 3 19 1 7 9 7 11 7 8 10 18 28 17 31 2 4 8 2 3 3 2 22 4 9 4 7 2 9 15 8 2 3 19 5 24 3 10 11 5 9 20 8 4 11 10 18 9 13 34 5 34 2 9 24 6 21 16 6 12 26 2 2 2 6 11 2 14 3 8 2 12 2 19 8 3 18 23 5 21 23 8 4 0
44 67
25 74
24 79
59 73
4 81
42 66
48 55
15 38
35 63
16 ...

output:

22
50
56
0
78
23
0
22
29
24
38
37
17
57
0
6
0
58
52
4
64
44
0
37
75
75
34
89
0
4
0
12
39
0
0
69
53
14
38
13
36
30
0
7
46
83
28
6
44
22
40
50
24
26
36
49
0
0
6
49
27
78
0
37
11
49
16
50
25
30
37
58
64
28
62
36
0
52
0
95
34
4
50
17
0
27
44
0
0
21
44
66
69
0
39
25
0
2
63
0


result:

ok 100 numbers

Test #8:

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

input:

100 100
0 1 0 1 0 1 1 1 0 2 1 1 2 0 1 1 0 3 0 0 0 0 0 0 0 0 1 2 2 0 0 0 0 1 0 0 1 2 0 0 1 0 0 3 0 1 0 0 3 0 0 0 1 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 2 0 0 0 4 0 1 1 0 1 0 2 2 0 0 1
41 53
31 36
78 99
60 86
1 67
3 92
89 92
60 70
42 56
42 46
39 84
40 66
9 27
75 78
33 94
17 53...

output:

13
6
22
27
67
90
3
11
15
5
46
27
19
4
62
37
84
35
53
4
47
95
55
63
24
39
22
51
67
21
55
36
24
16
33
74
4
16
63
81
41
14
3
54
6
40
36
33
29
32
14
60
13
17
73
44
34
2
14
79
59
13
75
72
31
10
22
57
23
37
74
2
6
6
38
5
4
62
66
22
33
0
23
21
12
54
75
6
8
16
37
36
3
53
63
18
67
60
31
19


result:

ok 100 numbers

Test #9:

score: -100
Runtime Error

input:

300000 300000
216504 101790 177261 84423 215788 67188 170620 125383 222808 149722 190483 152974 27524 172557 109218 201761 138030 177265 270417 244027 29296 13565 108388 270622 75102 137755 134081 21988 249714 268911 178911 39288 197287 232628 152784 226739 40134 213404 230781 181323 235763 55745 44...

output:


result: