QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#519682#6509. Not Another Range Query ProblemCrysflyWA 22ms72904kbC++172.4kb2024-08-14 23:49:492024-08-14 23:49:49

Judging History

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

  • [2024-08-14 23:49:49]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:72904kb
  • [2024-08-14 23:49:49]
  • 提交

answer

// what is matter? never mind. 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 1000006
#define inf 0x3f3f3f3f

int n,m,a[maxn];
char s[maxn];
int ql[maxn],qr[maxn],qk[maxn],res[maxn];
vi qs[maxn];

//int fa[maxn];
//int gf(int x){
//	while(x!=fa[x])x=fa[x]=fa[fa[x]];
//	return x;
//}
int tim[maxn];

int L[maxn],R[maxn];
void del(int u){
	R[L[u]]=R[u],L[R[u]]=L[u];
}
vi de[maxn];
void get_tim(){
	For(i,0,n+1) L[i]=max(0,i-1),R[i]=min(n+1,i+1);
	vi o;
	For(i,1,n) tim[i]=0;
	For(i,1,n) if(i==1 || a[i]!=a[i-1]) o.pb(i);
	int nowt=0;
	while(o.size()){
		++nowt;
		vi o2;
		for(int u:o){
			del(u),tim[u]=nowt;
			o2.pb(R[u]);
		}
		o.clear();
		for(int x:o2){
			if(!tim[x] && (L[x]==0 || a[x]!=a[L[x]])) o.pb(x);
		}
	}
}

struct bit{
	vector<int>tr;
	int n;
	void init(int N){n=N,tr=vector<int>(N+1,0);}
	void add(int x,int y){for(;x<=n;x+=x&-x)tr[x]+=y;}
	int ask(int x){
		int s=0;
		for(;x;x^=x&-x)s+=tr[x];
		return s;
	}
	void down(){For(i,1,n)tr[i]+=tr[i^(i&-i)];}
}tr;

void solve(int op){
	tr.init(n);
	For(i,1,n) tr.add(i,1);
	For(i,1,n){
		for(int x:de[i]) tr.add(x,-1);
		for(int id:qs[i]){
			if(op==1) res[id]+=tr.ask(qr[id]);
			else res[id]-=tr.ask(ql[id]-1);
		}
	}
}

signed main()
{
	n=read(),m=read();
	scanf("%s",s+1);
	For(i,1,n) a[i]=(s[i]&1);
	For(i,1,m) {
		ql[i]=read(),qr[i]=read(),qk[i]=read();
		if(!qk[i]) res[i]=qr[i]-ql[i]+1;
	}
	
	// del left
	get_tim();
	For(i,1,n) de[tim[i]].pb(i);
	For(i,1,m) qs[qk[i]].pb(i);
	solve(1);
	
	reverse(a+1,a+n+1);
	get_tim();
	reverse(a+1,a+n+1),reverse(tim+1,tim+n+1);
	For(i,1,n) de[i].clear();
	For(i,1,n) de[tim[i]].pb(i);
	solve(-1);
	
	For(i,1,m) printf("%d\n",res[i]);
	return 0;
}
/*

*/

详细

Test #1:

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

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
Wrong Answer
time: 22ms
memory: 72904kb

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
-8
0
-6
-2
0
0
10
18
1
0
57
0
-2
11
0
3
0
0
3
0
0
0
0
0
-1
0
0
-2
0
-7
0
-5
0
19
0
0
-2
12
5
0
0
2
-6
0
0
-2
10
12
0
0
0
5
0
8
0
1
16
-1
19
29
40
21
12
26
0
21
6
0
10
18
0
3
-1
2
5
0
0
5
0
0
-4
51
0
0
-1
18
11
0
20
5
9
10
0
16
22
0
20
0
26
0
0
0
0
0
0
11...

result:

wrong answer 22nd numbers differ - expected: '0', found: '-8'