QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#281339#7845. Fast ForwardUSP_USP_USP#AC ✓404ms354832kbC++201.4kb2023-12-10 02:57:102023-12-10 02:57:10

Judging History

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

  • [2023-12-10 02:57:10]
  • 评测
  • 测评结果:AC
  • 用时:404ms
  • 内存:354832kb
  • [2023-12-10 02:57:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
#define pb push_back
void dbg_out() { cerr << endl; }
template<typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) {cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }

const int MAXN = 2e6+5;

const int L = 20;

int up[MAXN][L];

void solve(){
	int n,c;
	cin >> n >> c;

	vector<int> a(n);
	int sum = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}

	vector<int> b(2*n);
	for(int i = 0; i < n; i++){
		b[i] = a[i];
		b[i+n] = a[i];
	}
	auto preb = b;
	for(int i = 1; i < 2*n; i++){
		preb[i] = preb[i-1] + b[i];
	}

	auto sum_interval = [&](int i, int j){
		return preb[j] - (i ? preb[i-1] : 0);
	};
	
	for(int i = 0; i < 2*n; i++){
		int l = i;
		int r = 2*n;
		while(l < r){
			int m = (l+r)/2;
			if(sum_interval(i,m) >= c){
				r =m;
			}else{
				l = m+1;
			}
		}
		up[i][0] = r+1;
	}
	for(int j = 0; j < L; j++){
		up[2*n][j] = 2*n;
		up[2*n+1][j] = 2*n+1;
	}
	
	for(int i = 2*n-1; i >= 0; i--){
		for(int j = 1; j < L; j++){
			up[i][j] = up[ up[i][j-1]][j-1];
		}
	}
	for(int i = 0; i < n; i++){
		int ans = 0;
		int x = i;
		for(int j = L-1; j >= 0; j--){
			if(up[x][j] < i+n){
				ans += (1<<j);
				x = up[x][j];
			}
		}
		cout << ans << ' ';
	}
	cout << '\n';
}

signed main(){
	ios::sync_with_stdio(false); cin.tie(0);
	solve();
}

详细

Test #1:

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

input:

7 7
1 1 1 1 1 1 1

output:

0 0 0 0 0 0 0 

result:

ok single line: '0 0 0 0 0 0 0 '

Test #2:

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

input:

3 3
1 1 3

output:

0 1 1 

result:

ok single line: '0 1 1 '

Test #3:

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

input:

10 5
4 1 5 5 1 3 2 1 5 2

output:

5 4 5 4 4 5 4 4 5 4 

result:

ok single line: '5 4 5 4 4 5 4 4 5 4 '

Test #4:

score: 0
Accepted
time: 216ms
memory: 354640kb

input:

1000000 22867
553 901 645 485 940 745 166 365 357 935 102 534 812 329 56 650 100 992 528 829 755 128 190 916 245 942 132 359 367 562 636 77 62 562 404 487 545 298 71 697 784 523 957 383 332 650 636 822 245 379 792 605 239 69 723 867 925 308 511 975 808 341 341 125 940 833 810 282 567 754 893 59 618 ...

output:

21589 21589 21589 21589 21589 21589 21589 21589 21589 21590 21590 21590 21590 21590 21590 21590 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 ...

result:

ok single line: '21589 21589 21589 21589 21589 ... 21589 21589 21589 21589 21589 '

Test #5:

score: 0
Accepted
time: 154ms
memory: 354612kb

input:

1000000 1000000000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1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

ok single line: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 '

Test #7:

score: 0
Accepted
time: 404ms
memory: 354832kb

input:

1000000 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999...

result:

ok single line: '999999 999999 999999 999999 99...99 999999 999999 999999 999999 '

Test #8:

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

input:

10 3
8 2 4 3 6 3 3 7 9 8

output:

8 8 9 8 8 8 8 8 8 8 

result:

ok single line: '8 8 9 8 8 8 8 8 8 8 '

Test #9:

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

input:

100 8
4 4 1 1 1 3 1 2 3 3 2 3 5 2 1 3 2 1 1 1 5 2 2 4 3 5 4 2 3 3 3 3 2 5 2 2 4 1 2 5 3 4 5 3 3 1 4 5 5 1 2 4 3 1 1 2 3 1 5 5 4 2 3 5 5 1 1 5 3 4 3 4 2 1 2 3 4 1 5 1 1 3 1 5 1 4 3 4 1 2 4 3 4 2 5 4 4 1 2 4

output:

30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 31 30 30 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 31 30 30 31 30 30 31 31 30 30 31 30 30 31 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 

result:

ok single line: '30 30 30 31 30 30 30 30 30 30 ... 30 30 30 30 30 30 30 30 30 30 '

Test #10:

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

input:

1000 12
24 12 12 8 14 20 5 20 11 4 25 23 16 24 6 7 14 7 11 6 7 16 25 5 19 8 8 20 3 10 9 8 1 25 9 2 20 2 17 22 7 5 21 25 7 23 15 24 4 17 2 1 20 10 13 19 4 19 9 14 11 7 13 4 19 12 23 19 6 20 20 17 5 25 8 15 24 18 16 2 12 23 20 10 12 19 7 23 3 25 1 16 9 6 4 6 4 10 4 1 17 12 15 18 13 8 19 22 10 25 3 16 ...

output:

658 657 657 657 658 657 657 658 657 657 657 657 657 657 657 657 657 657 657 657 657 657 657 657 658 657 657 657 657 657 657 657 657 658 657 658 658 657 658 657 657 657 657 657 657 658 657 657 657 658 657 658 658 657 658 657 657 658 657 658 657 657 657 657 658 657 657 657 657 658 657 657 657 658 657 ...

result:

ok single line: '658 657 657 657 658 657 657 65...57 658 657 658 657 657 658 657 '

Test #11:

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

input:

1000 37
44 94 6 47 73 16 60 49 73 62 97 28 21 6 70 89 33 10 49 55 8 2 72 29 4 29 91 17 94 100 36 43 83 3 22 6 1 75 50 95 49 12 53 35 95 9 3 92 84 26 77 93 60 40 96 29 19 25 9 35 41 5 6 88 36 27 95 88 22 79 14 63 24 67 72 61 51 3 59 65 50 63 12 13 73 18 14 50 51 2 7 71 10 44 79 38 84 23 100 63 58 67 ...

output:

697 696 696 697 696 696 697 696 696 696 696 696 696 696 697 696 696 696 696 696 696 697 697 696 696 696 696 696 697 696 696 697 696 696 697 697 697 697 696 696 696 696 697 696 697 696 697 697 696 696 697 696 696 696 696 696 697 696 697 696 696 696 697 697 696 696 696 696 696 697 696 697 696 697 696 ...

result:

ok single line: '697 696 696 697 696 696 697 69...96 697 696 696 696 696 696 696 '

Test #12:

score: 0
Accepted
time: 283ms
memory: 354732kb

input:

1000000 65
64 91 62 47 79 84 60 12 62 43 98 90 51 55 80 11 75 92 56 95 18 34 99 3 93 48 82 75 84 86 1 21 25 22 48 76 4 13 92 72 42 65 56 29 43 56 42 5 36 27 38 73 9 5 97 12 68 79 77 82 17 66 84 35 9 28 70 4 64 36 82 91 13 72 90 7 65 70 82 87 24 8 72 57 61 68 80 44 39 43 38 9 98 75 54 34 53 25 99 91 ...

output:

529609 529609 529609 529609 529609 529609 529609 529609 529609 529609 529609 529609 529609 529609 529609 529609 529610 529609 529609 529610 529609 529610 529610 529609 529610 529609 529610 529609 529609 529609 529609 529610 529610 529610 529609 529610 529609 529610 529610 529609 529609 529610 529609...

result:

ok single line: '529609 529609 529609 529609 52...10 529609 529609 529609 529610 '

Test #13:

score: 0
Accepted
time: 215ms
memory: 354640kb

input:

1000000 990
4 89 22 24 73 63 81 78 71 99 15 16 61 5 33 5 69 87 56 57 60 4 80 76 54 64 77 31 43 63 87 3 6 54 17 13 17 35 95 44 6 15 71 4 7 41 65 43 66 79 59 45 43 27 27 84 82 49 21 71 51 15 90 32 82 30 49 62 95 53 42 27 92 97 98 28 29 22 35 75 68 43 78 26 34 13 16 28 55 22 56 96 26 60 2 16 9 65 89 48...

output:

49374 49374 49374 49374 49374 49373 49373 49373 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49373 49373 49373 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49373 ...

result:

ok single line: '49374 49374 49374 49374 49374 ... 49374 49374 49374 49374 49374 '

Test #14:

score: 0
Accepted
time: 276ms
memory: 354668kb

input:

1000000 114
667 871 367 86 37 432 705 325 483 395 779 392 262 847 377 319 155 671 523 29 439 943 694 795 118 246 644 369 302 103 199 846 748 826 183 256 408 947 628 670 257 219 570 840 141 936 348 901 787 138 665 886 489 339 678 819 212 406 161 974 396 752 491 323 525 319 763 524 847 19 70 505 165 2...

output:

893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893285 893284 893284 893284 893284 893284 893284 893284 893284 893284 893285 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284...

result:

ok single line: '893284 893284 893284 893284 89...84 893284 893284 893284 893284 '

Test #15:

score: 0
Accepted
time: 248ms
memory: 354628kb

input:

1000000 4739
474 560 955 876 736 103 890 75 806 270 824 498 94 754 955 260 597 309 885 227 709 268 926 673 166 389 729 395 305 34 224 736 263 605 773 435 399 969 416 93 909 355 71 174 964 496 219 157 500 930 36 745 505 189 989 827 181 940 743 860 12 661 385 793 43 216 362 516 415 74 154 594 909 780 ...

output:

98635 98635 98634 98634 98634 98635 98635 98635 98635 98635 98635 98634 98634 98634 98634 98635 98635 98635 98635 98635 98634 98634 98634 98634 98635 98635 98635 98635 98635 98635 98635 98634 98634 98634 98634 98634 98635 98635 98635 98635 98635 98634 98634 98634 98634 98634 98635 98635 98635 98635 ...

result:

ok single line: '98635 98635 98634 98634 98634 ... 98634 98634 98634 98635 98635 '