QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#770793#9731. Fuzzy Rankingtjf4RE 541ms25632kbC++203.6kb2024-11-22 00:15:312024-11-22 00:15:32

Judging History

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

  • [2024-11-25 12:28:53]
  • hack成功,自动添加数据
  • (/hack/1257)
  • [2024-11-22 00:15:32]
  • 评测
  • 测评结果:RE
  • 用时:541ms
  • 内存:25632kb
  • [2024-11-22 00:15:31]
  • 提交

answer

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<char> vc;
const int inf=0x3f;
const int N=2e5+10;
ll n,m,k,bk,nx[N],mi[N],idk[N],ls[N],rs[N],f[505][505],g[505][505];
vi e[N],h[N],fk[505][505],gk[505][505];
void init() {
	bk=sqrt(n);
	for(int i=1;i<=n;i++) idk[i]=(i-1)/bk+1;
	for(int i=1;i<=n;i++) rs[idk[i]]=i;
	for(int i=n;i>=1;i--) ls[idk[i]]=i;
	for(int i=1;i<=k;i++) {
		for(int j=1;j<=idk[n];j++) {
			fk[i][j].clear();
			gk[i][j].clear();
			g[i][j]=0;
		}
	}
	for(int i=1;i<=k;i++) {
		for(int j=1;j<=n;j++) {
			fk[i][idk[j]].push_back(h[i][j-1]);
			g[i][idk[j]]+=(j-h[i][j-1]);
		}
		for(int j=1;j<=idk[n];j++) {
			sort(fk[i][j].begin(),fk[i][j].end());
			for(auto v:fk[i][j]) {
				ll w=v;
				if(!gk[i][j].empty()) w+=gk[i][j].back();
				gk[i][j].push_back(w);
			}
		}
	}
}
ll qry(ll id,ll l,ll r) {
	ll ans=0;
	for(int i=idk[l]+1;i<=idk[r]-1;i++) {
		ans+=g[id][i];
		auto it=lower_bound(fk[id][i].begin(),fk[id][i].end(),l)-fk[id][i].begin();
		if(it==0) continue;
		ans-=(it*l-gk[id][i][it-1]);
	}
	if(idk[l]==idk[r]) {
		for(int i=l+1;i<=r;i++) {
			ll lf=h[id][i-1];
			if(lf<l) ans+=(i-l);
			else ans+=(i-lf);
		}
	}
	else {
		for(int i=l+1;i<=rs[idk[l]];i++) {
			ll lf=h[id][i-1];
			if(lf<l) ans+=(i-l);
			else ans+=(i-lf);
		}
		for(int i=ls[idk[r]];i<=r;i++) {
			ll lf=h[id][i-1];
			if(lf<l) ans+=(i-l);
			else ans+=(i-lf);
		}
	}
	return ans;
}
int main() {
	IOS
	int T;
	cin>>T;
	while(T--) {
		cin>>n>>k>>m;
		vector<vi> mp(k+5,vi(n+5,0));
		for(int i=0;i<=k+1;i++) {
			e[i].clear();
			h[i].clear();
		}
		for(int i=1;i<=k;i++) {
			for(int j=1;j<=n;j++) {
				ll x; cin>>x;
				e[i].push_back(x); 
				mp[i][x]=j;
			}
		}
		if(k<n) {
			for(int i=1;i<=k;i++) {
				for(int j=1;j<=k;j++) nx[j]=mi[j]=n+1;
				for(int j=n;j>=1;j--) {
					ll x=e[i][j-1],as=j;
					for(int r=1;r<=k;r++) {
						while(nx[r]>mp[r][x]) {
							--nx[r];
							ll now_r=e[r][nx[r]-1];
							mi[r]=min(mi[r],mp[i][now_r]);
						}
						as=min(as,mi[r]);
					}
					h[i].push_back(as);
				}
				reverse(h[i].begin(),h[i].end());
			}
			init();
			ll mask=0;
			while(m--) {
				ll id,l,r;
				cin>>id>>l>>r;
				id=(id+mask)%k+1;
				l=(l+mask)%n+1;
				r=(r+mask)%n+1;
				ll ans=qry(id,l,r);
//				if(ans<0) ans=0;
				cout<<ans<<'\n';
				mask=ans;
			}
		}
		else {
			for(int i=1;i<=n;i++) {
				for(int j=1;j<=n;j++) {
					f[i][j]=0;
				}
			}
			for(int i=1;i<=k;i++) {
				for(int j=1;j<=n;j++) {
					for(int r=j;r<=n;r++) {
						int x=e[i][j-1];
						int y=e[i][r-1];
						f[x][y]=1;
					}
				}
			}
			for(int r=1;r<=n;r++) {
				for(int i=1;i<=n;i++) {
					for(int j=1;j<=n;j++) {
						f[i][j]|=(f[i][r]&f[r][j]);
					}
				}
			}
			for(int i=1;i<=k;i++) {
				for(int j=1;j<=n;j++) {
					int x=e[i][j-1],as=j;
					for(int r=1;r<j;r++) {
						int y=e[i][r-1];
						if(f[x][y]) {
							as=r;
							break;
						}
					}
					h[i].push_back(as);
				}
			}
			ll mask=0;
			while(m--) {
				ll id,l,r;
				cin>>id>>l>>r;
				id=(id+mask)%k+1;
				l=(l+mask)%n+1;
				r=(r+mask)%n+1;
				ll ans=0;
				for(int i=l+1;i<=r;i++) {
					ll lf=h[id][i-1];
					if(lf<l) ans+=(i-l);
					else ans+=(i-lf);
				}
				if(ans<0) ans=0;
				cout<<ans<<'\n';
				mask=ans;
			}
		}
	}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 13912kb

input:

2
5 2 2
1 2 3 4 5
5 4 3 2 1
1 0 2
1 2 1
5 3 3
1 2 3 4 5
1 3 2 4 5
1 2 3 5 4
0 0 2
0 2 3
1 0 3

output:

3
10
1
1
2

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 15ms
memory: 5572kb

input:

2000
10 10 10
4 5 3 6 8 9 2 1 7 10
4 5 6 3 8 9 1 2 10 7
5 4 3 6 8 9 1 2 7 10
4 5 6 3 8 9 1 2 7 10
4 5 3 6 8 9 2 1 10 7
4 5 6 3 8 9 1 2 10 7
5 4 6 3 8 9 1 2 7 10
5 4 6 3 8 9 1 2 10 7
4 5 6 3 8 9 2 1 7 10
5 4 3 6 8 9 2 1 10 7
3 1 6
5 7 8
0 2 3
7 9 9
2 1 9
6 1 6
7 2 3
0 0 4
1 8 1
1 8 7
10 10 10
9 10 5 ...

output:

1
1
0
0
3
2
0
2
2
4
1
0
1
1
1
1
2
4
4
3
1
6
28
0
0
10
10
6
6
15
0
3
10
6
16
6
11
1
2
1
1
6
3
3
0
4
5
3
4
1
1
3
2
4
0
3
4
4
4
4
0
0
1
1
2
0
0
1
2
1
1
0
0
1
4
3
0
4
4
1
3
6
16
16
0
11
16
1
4
15
1
4
2
0
0
2
0
1
2
4
0
0
0
0
0
0
0
0
0
0
1
0
0
6
3
0
3
4
0
0
0
0
0
0
0
0
0
0
0
0
3
0
0
1
3
1
0
0
3
3
9
1
9
4
...

result:

ok 20000 lines

Test #3:

score: 0
Accepted
time: 23ms
memory: 5584kb

input:

8000
5 5 10
3 5 2 4 1
3 2 5 4 1
3 5 2 4 1
3 5 2 4 1
3 5 2 4 1
1 1 1
4 1 3
1 0 3
4 2 3
1 0 1
3 2 3
1 2 3
3 0 2
1 1 3
1 1 2
5 5 10
5 3 1 2 4
3 5 1 2 4
5 3 1 2 4
3 5 1 2 4
5 3 1 2 4
0 0 1
2 0 1
4 1 2
1 3 4
2 0 1
4 3 3
1 4 4
1 3 4
0 0 4
0 0 3
5 5 10
2 3 4 1 5
5 1 4 3 2
1 3 4 2 5
2 3 4 1 5
5 1 3 4 2
1 2 ...

output:

0
1
1
0
0
0
0
1
0
1
1
0
0
0
1
0
0
0
1
0
3
0
3
1
0
3
1
6
1
0
0
0
0
0
0
0
0
0
0
0
1
1
2
1
0
3
0
0
3
0
1
0
0
0
0
0
0
1
0
0
6
1
0
6
0
3
3
3
0
0
3
3
6
1
10
1
3
0
1
0
3
1
0
0
1
0
1
1
1
2
0
0
0
0
0
0
0
0
0
0
0
0
3
1
3
3
1
3
1
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
1
6
0
6
6
1
1
1
0
1
1
0
0
1
0
0
0
3
0
1
1
0
2
3
3...

result:

ok 80000 lines

Test #4:

score: 0
Accepted
time: 18ms
memory: 5584kb

input:

8000
5 5 5
1 3 5 2 4
5 3 2 1 4
5 2 1 3 4
3 1 2 5 4
1 3 2 5 4
1 1 2
1 4 0
1 4 1
2 2 2
4 1 3
5 5 5
2 3 4 1 5
2 3 4 1 5
2 3 4 5 1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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
...

result:

ok 200000 lines

Test #6:

score: 0
Accepted
time: 16ms
memory: 6520kb

input:

10
20 1000 2000
2 5 1 3 12 16 14 15 7 4 19 13 18 10 20 9 11 8 6 17
5 2 12 1 16 3 19 4 7 15 14 18 13 10 9 20 11 8 6 17
2 5 1 16 12 3 7 14 4 19 15 13 18 10 20 9 11 17 6 8
2 5 1 16 3 12 15 7 4 14 19 18 13 10 9 20 11 8 6 17
5 2 3 12 1 16 14 7 4 15 19 18 13 10 20 9 11 6 17 8
2 5 3 1 12 16 19 15 7 4 14 18...

output:

11
0
11
10
1
11
5
10
10
5
13
2
0
18
2
14
2
18
10
13
1
1
0
1
4
7
6
0
15
11
1
4
6
19
3
9
3
1
0
20
2
16
1
0
3
2
3
0
18
1
17
1
1
8
1
5
17
1
3
6
1
2
15
15
2
1
0
3
18
22
0
1
2
15
13
12
20
3
0
9
15
1
4
17
22
16
8
6
13
0
7
11
15
19
15
6
7
10
17
12
9
1
11
1
0
4
6
17
1
17
6
5
1
1
16
14
3
1
12
18
1
0
18
12
17
...

result:

ok 20000 lines

Test #7:

score: 0
Accepted
time: 17ms
memory: 6340kb

input:

33
3 2000 2000
1 2 3
2 1 3
2 1 3
2 1 3
1 2 3
2 1 3
2 1 3
1 2 3
2 1 3
1 2 3
2 1 3
2 1 3
2 1 3
1 2 3
2 1 3
2 1 3
2 1 3
1 2 3
2 1 3
2 1 3
1 2 3
1 2 3
2 1 3
1 2 3
2 1 3
1 2 3
2 1 3
1 2 3
2 1 3
2 1 3
1 2 3
2 1 3
2 1 3
2 1 3
1 2 3
2 1 3
1 2 3
1 2 3
2 1 3
1 2 3
1 2 3
1 2 3
1 2 3
2 1 3
2 1 3
1 2 3
2 1 3
2 1...

output:

1
1
0
1
0
0
1
0
0
0
0
0
0
1
1
0
0
0
1
1
0
0
0
0
1
0
1
0
0
0
0
1
0
0
1
0
1
0
0
0
1
0
1
0
0
0
0
1
0
0
1
1
0
1
0
0
1
0
1
1
0
0
0
1
1
0
1
1
0
1
0
1
0
0
0
1
0
0
0
1
1
1
1
0
0
0
1
0
1
0
0
0
0
1
1
0
0
1
1
1
0
1
1
0
0
1
0
0
0
0
1
0
0
0
0
0
0
0
1
1
1
0
0
0
0
1
0
1
0
1
0
0
0
1
1
1
0
0
0
0
0
0
0
0
0
0
1
1
0
0
...

result:

ok 66000 lines

Test #8:

score: 0
Accepted
time: 71ms
memory: 8548kb

input:

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

output:

1
4
2
3
2
4
0
2
1
1
1
0
0
4
0
4
3
2
2
1
4
0
4
0
2
2
4
2
2
0
2
2
1
0
0
1
3
2
2
0
0
0
3
2
0
1
4
1
2
2
3
1
3
0
2
1
1
4
2
1
0
0
3
0
0
2
0
2
4
3
0
4
0
0
3
0
2
2
0
4
3
4
2
3
2
0
2
0
1
1
2
1
2
1
4
0
1
0
1
2
0
2
4
1
0
2
4
2
3
1
4
2
0
2
0
2
0
2
2
0
1
2
1
2
0
3
2
1
2
1
1
4
1
1
1
2
1
2
2
1
0
2
0
1
0
1
1
1
0
2
...

result:

ok 200000 lines

Test #9:

score: 0
Accepted
time: 116ms
memory: 12324kb

input:

1
316 632 200000
36 93 100 184 246 134 89 157 219 9 18 29 8 109 159 3 255 66 257 27 290 286 283 132 216 175 167 208 238 31 220 296 271 113 269 127 156 300 121 267 99 122 90 288 64 210 28 144 262 60 53 6 96 268 276 279 13 174 287 78 295 72 143 155 146 197 107 35 24 88 187 110 163 204 2 25 226 119 164...

output:

7
87
10
47
74
55
79
64
19
2
104
21
54
1
4
72
81
57
12
74
28
77
82
77
7
22
56
6
81
4
28
24
56
19
25
7
7
4
64
68
51
16
95
23
67
31
33
45
72
69
65
7
24
11
85
25
0
1
0
20
72
43
56
12
16
76
98
91
50
84
23
71
8
14
22
49
64
3
24
2
15
5
90
11
26
40
3
12
4
23
88
65
34
42
25
4
80
3
6
20
41
83
12
10
43
24
3
77...

result:

ok 200000 lines

Test #10:

score: 0
Accepted
time: 541ms
memory: 25632kb

input:

1
632 316 200000
625 142 323 331 85 521 376 51 411 31 418 11 16 66 112 611 459 622 148 247 122 587 249 141 20 88 439 334 233 474 305 381 203 559 228 595 326 535 128 449 138 28 86 56 109 102 428 194 612 256 466 598 189 539 237 59 225 528 200 330 490 560 133 57 590 632 422 213 340 310 49 195 41 217 19...

output:

60
34
45
304
31
71
52
36
123
38
76
28
200
223
55
58
11
275
202
76
285
30
154
113
40
48
355
332
358
33
240
46
29
91
147
75
318
62
162
200
171
124
228
31
285
59
16
206
114
44
163
87
53
65
221
298
23
172
123
91
298
14
57
6
8
71
1
84
3
2
58
20
6
111
244
220
25
137
86
269
134
254
68
64
129
14
65
108
43
3...

result:

ok 200000 lines

Test #11:

score: 0
Accepted
time: 219ms
memory: 12876kb

input:

1
447 447 200000
108 218 332 238 439 329 405 417 75 380 227 395 285 112 24 290 141 390 269 155 364 36 79 403 170 284 348 250 93 331 232 90 419 228 21 424 213 365 353 404 274 144 146 291 88 29 44 12 362 233 312 369 400 95 142 17 327 111 414 86 58 314 163 401 358 197 441 157 160 40 220 180 283 10 63 6...

output:

720
254
101
688
77
209
15
516
644
262
61
102
719
85
49
52
471
94
275
145
3
714
101
385
407
241
154
441
839
247
124
278
100
290
408
290
567
42
72
320
296
528
471
420
293
295
688
516
354
159
812
468
487
671
190
514
396
154
887
64
119
125
604
27
901
669
651
148
432
673
291
183
3
123
946
722
783
382
367...

result:

ok 200000 lines

Test #12:

score: -100
Runtime Error

input:

2
10000 10 100000
9169 6526 4977 9620 6327 8688 1778 4867 8252 2611 762 6164 1606 5796 6803 7006 5759 9972 8099 6268 5700 9868 896 2146 7128 1326 2696 2311 8764 6495 8013 6340 8057 6116 8447 5480 6736 9968 1048 1357 9013 8647 2334 8332 1514 6336 1486 5441 2963 2814 6910 4862 9616 1340 9839 3105 3703...

output:


result: