QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#143193#6509. Not Another Range Query Problem275307894aTL 0ms12024kbC++141.6kb2023-08-20 21:11:072023-08-20 21:11:10

Judging History

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

  • [2023-08-20 21:11:10]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:12024kb
  • [2023-08-20 21:11:07]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=5e5+5,M=2e3+5,K=31650,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,m,k,x,y,z;char s[N];
int pre[N],nxt[N];
int dt[N],ds[N];
int ans[N];
int main(){
	int i,j;scanf("%d%d",&n,&m);scanf("%s",s+1);
	for(i=1;i<=n+1;i++) pre[i]=i-1,nxt[i-1]=i;
	vector<int> q1;
	for(i=2;i<=n;i++) if(s[i]^s[pre[i]]) q1.emplace_back(i);
	for(i=1;i<=n;i++){
		for(int j:q1) dt[j]=i,ds[j]=pre[j];
		vector<int> q2;q2.clear();
		reverse(q1.begin(),q1.end());
		for(int j:q1) nxt[pre[j]]=nxt[j],pre[nxt[j]]=pre[j],q2.emplace_back(nxt[j]);
		sort(q2.begin(),q2.end());q2.erase(unique(q2.begin(),q2.end()),q2.end());
		q1.clear();for(int j:q2) if(j<=n&&pre[j]&&s[j]^s[pre[j]]) q1.emplace_back(j);
	}
	for(i=1;i<=n;i++) if(!dt[i]) dt[i]=INF;
	// for(i=1;i<=16;i++) cerr<<dt[i]<<' '<<ds[i]<<'\n';
	// for(i=7;i<=43;i++) cerr<<s[i];cerr<<'\n';
	for(i=1;i<=m;i++){
		scanf("%d%d%d",&x,&y,&z);
		int p=0,q=y+1;
		for(j=x;j<=y;j++){
			if(ds[j]<x) p++;else p=max(p,dt[j]);
			if(p>z){q=j;break;}
		}
		cerr<<q<<'\n';
		for(j=q;j<=y;j++) ans[i]+=(dt[j]>z);
		printf("%d\n",ans[i]);
	}
}

詳細信息

Test #1:

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

input:

9 7
100110001
2 5 1
3 6 1
4 8 2
2 7 1
1 9 1
1 9 0
1 9 8

output:

2
1
1
3
4
9
0

result:

ok 7 numbers

Test #2:

score: -100
Time Limit Exceeded

input:

100 100000
0000011010101000111011110110000111110101101010111111101011011010111001111010111000001000011000001010
76 99 3
25 84 7
45 83 11
10 12 10
69 86 4
27 28 1
22 42 42
4 86 25
26 91 22
20 81 17
50 78 0
77 93 50
31 50 34
7 46 13
78 89 0
79 98 0
2 84 33
58 93 11
56 75 2
55 77 68
7 9 41
44 46 11
47 ...

output:

8
13
4
0
3
0
0
0
0
4
29
0
0
0
12
20
0
0
5
0
0
0
0
0
0
0
0
10
18
1
0
57
0
0
11
0
3
0
0
3
0
0
0
0
0
0
0
0
0
0
0
0
0
0
19
0
0
0
12
5
0
0
2
0
0
0
0
10
12
0
0
0
5
0
8
0
1
16
0
19
29
40
21
12
26
0
21
6
0
10
18
0
3
0
2
5
0
0
5
0
0
0
51
0
0
0
18
11
0
20
5
9
10
0
16
22
0
20
0
26
0
0
0
0
0
0
11
46
59
2
9
43
1...

result: