QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#297090#7182. Very Sparse TableAlphaMale06AC ✓527ms22636kbC++142.2kb2024-01-03 22:38:482024-01-03 22:38:49

Judging History

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

  • [2024-01-03 22:38:49]
  • 评测
  • 测评结果:AC
  • 用时:527ms
  • 内存:22636kb
  • [2024-01-03 22:38:48]
  • 提交

answer

#include <bits/stdc++.h>

/*
	Oce nas,
	koji si na nebesima,
	da se sveti ime Tvoje,
	da dodje carstvo Tvoje,
	da bude volja Tvoja,
	i na zemlji, kao i na nebu.
	
	Hleb nas nasusni daj nam danas,
	i oprosti nam dugove nase,
	kao sto i mi oprastamo duznicima svojim,
	i ne uvedi nas u iskusenje,
	no izbavi nas od zloga.
	
	Jer je Tvoje Carstvo,
	i sila, i slava,
	u vekove vekova.
	
	Amin.
*/

using namespace std;
typedef vector<int> vc;
typedef vector<vector<int>> vvc;
using ll = long long;
using ld = long double;
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(), (x).end()
#define int long long


const int N = (2<<16)+2;
int n;

vector<int> edges[N];

struct add{
	int a, b, c;
};

vector<add> added;

void createtable(int l, int r){
	if(r-l+1<=4)return;
	int sqr=sqrt(r-l+1);
	vector<int> imp;
	for(int i=l+sqr; i < r; i+=sqr){
		imp.pb(i);
	}
	int prev=l-1;
	for(int i=0; i< imp.size(); i++){
		for(int j=imp[i]-2; j>prev; j--){
			edges[j].pb(imp[i]);
			added.pb({j, j+1, imp[i]});
		}
		prev=imp[i];
	}
	int nxt=r+1;
	for(int i=imp.size()-1; i>=0; i--){
		for(int j=imp[i]+2; j<nxt; j++){
			edges[imp[i]].pb(j);
			added.pb({imp[i], j-1, j});
		}
		nxt=imp[i];
	}
	for(int i=imp.size()-2; i>=0; i--){
		edges[imp[i]].pb(imp[i+1]);
		added.pb({imp[i], imp[i+1]-1, imp[i+1]});
		for(int j=i+2; j<imp.size(); j++){
			edges[imp[i]].pb(imp[j]);
			added.pb({imp[i], imp[j-1], imp[j]});
		}
		
	}
	createtable(l, imp[0]-1);
	for(int i=1; i< imp.size(); i++)createtable(imp[i-1]+1, imp[i]-1);
	createtable(imp[imp.size()-1]+1, r);
}

void solve(){
	int n;
	cin >> n;
	createtable(0, n);
	for(int i=0; i< n; i++)edges[i].pb(i+1);
	cout << added.size() << '\n';
	for(add a : added){
		cout << a.a << " " << a.b << " " << a.c << '\n';
	}
	for(int i=0; i<n; i++){
		sort(all(edges[i]));
	}
	int q;
	cin >> q;
	while(q--){
		int l, r;
		cin >> l >> r;
		cout << l << " ";
		while(l<r){
			int mx=0;
			for(int to : edges[l]){
				if(to<=r)mx=to;
				else break;
			}
			cout << mx << " ";
			l=mx;
		}
		cout << '\n';
	}
}

signed main(){
	solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok edges: 7

Test #2:

score: 0
Accepted
time: 1ms
memory: 6612kb

input:

30
465
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10
0 11
0 12
0 13
0 14
0 15
0 16
0 17
0 18
0 19
0 20
0 21
0 22
0 23
0 24
0 25
0 26
0 27
0 28
0 29
0 30
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
2 3
2 4
2 5
2 6...

output:

46
3 4 5
2 3 5
1 2 5
0 1 5
8 9 10
7 8 10
6 7 10
13 14 15
12 13 15
11 12 15
18 19 20
17 18 20
16 17 20
23 24 25
22 23 25
21 22 25
25 26 27
25 27 28
25 28 29
25 29 30
20 21 22
20 22 23
20 23 24
15 16 17
15 17 18
15 18 19
10 11 12
10 12 13
10 13 14
5 6 7
5 7 8
5 8 9
20 24 25
15 19 20
15 20 25
10 14 15
...

result:

ok edges: 46

Test #3:

score: 0
Accepted
time: 319ms
memory: 6704kb

input:

736
200000
170 268
126 166
565 723
664 735
61 524
226 234
146 314
217 272
294 713
115 381
563 706
74 567
552 614
120 211
472 620
213 432
488 623
447 564
96 129
331 354
79 677
50 547
174 568
56 129
189 227
55 701
244 253
264 715
154 220
380 657
46 390
53 161
325 537
666 696
64 465
391 659
284 448
207...

output:

2662
25 26 27
24 25 27
23 24 27
22 23 27
21 22 27
20 21 27
19 20 27
18 19 27
17 18 27
16 17 27
15 16 27
14 15 27
13 14 27
12 13 27
11 12 27
10 11 27
9 10 27
8 9 27
7 8 27
6 7 27
5 6 27
4 5 27
3 4 27
2 3 27
1 2 27
0 1 27
52 53 54
51 52 54
50 51 54
49 50 54
48 49 54
47 48 54
46 47 54
45 46 54
44 45 54...

result:

ok edges: 2662

Test #4:

score: 0
Accepted
time: 527ms
memory: 22580kb

input:

65536
200000
51949 58727
7943 43298
6290 7369
41493 53070
24229 36675
28087 49947
11703 48217
19923 24739
2144 59777
53830 56793
13509 37211
2300 38595
27415 42879
24616 48531
58341 63327
20628 38407
48616 60290
7450 61685
37010 47595
22164 42732
19181 29850
35383 43587
39257 44397
19340 45183
34523...

output:

360565
254 255 256
253 254 256
252 253 256
251 252 256
250 251 256
249 250 256
248 249 256
247 248 256
246 247 256
245 246 256
244 245 256
243 244 256
242 243 256
241 242 256
240 241 256
239 240 256
238 239 256
237 238 256
236 237 256
235 236 256
234 235 256
233 234 256
232 233 256
231 232 256
230 2...

result:

ok edges: 360565

Test #5:

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

input:

0
0

output:

0

result:

ok edges: 0

Test #6:

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

input:

1
1
0 1

output:

0
0 1 

result:

ok edges: 0

Test #7:

score: 0
Accepted
time: 2ms
memory: 6536kb

input:

2
3
0 1
0 2
1 2

output:

0
0 1 
0 1 2 
1 2 

result:

ok edges: 0

Test #8:

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

input:

3
6
0 1
0 2
0 3
1 2
1 3
2 3

output:

0
0 1 
0 1 2 
0 1 2 3 
1 2 
1 2 3 
2 3 

result:

ok edges: 0

Test #9:

score: 0
Accepted
time: 521ms
memory: 22572kb

input:

65535
200000
35006 46944
17075 57351
24605 50445
5938 60705
15221 40233
28599 38915
1132 35574
8555 31494
13644 35806
44940 55401
9503 59206
21011 26540
41156 62487
57510 64305
9254 25610
17301 47249
34083 49167
48018 64394
38855 62175
15464 22525
23728 60275
54028 63810
22711 53902
5984 48625
5838 ...

output:

360573
254 255 256
253 254 256
252 253 256
251 252 256
250 251 256
249 250 256
248 249 256
247 248 256
246 247 256
245 246 256
244 245 256
243 244 256
242 243 256
241 242 256
240 241 256
239 240 256
238 239 256
237 238 256
236 237 256
235 236 256
234 235 256
233 234 256
232 233 256
231 232 256
230 2...

result:

ok edges: 360573

Test #10:

score: 0
Accepted
time: 523ms
memory: 22636kb

input:

64800
200000
55124 62263
24992 39760
32262 37059
25987 42889
10413 64701
7223 43221
45810 63205
11437 29357
10814 52096
1154 36319
10730 54157
18473 26729
9152 23374
5426 12744
3502 37577
5559 37160
30503 62433
12426 47332
14933 62086
8781 21527
27180 53773
29658 46742
20592 61553
8337 27197
8024 38...

output:

357078
252 253 254
251 252 254
250 251 254
249 250 254
248 249 254
247 248 254
246 247 254
245 246 254
244 245 254
243 244 254
242 243 254
241 242 254
240 241 254
239 240 254
238 239 254
237 238 254
236 237 254
235 236 254
234 235 254
233 234 254
232 233 254
231 232 254
230 231 254
229 230 254
228 2...

result:

ok edges: 357078

Extra Test:

score: 0
Extra Test Passed