QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#226185#4583. Concerto de Pandemicideograph_advantage#WA 636ms50120kbC++173.1kb2023-10-25 17:52:542023-10-25 17:52:55

Judging History

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

  • [2023-10-25 17:52:55]
  • 评测
  • 测评结果:WA
  • 用时:636ms
  • 内存:50120kb
  • [2023-10-25 17:52:54]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define iter(v) v.begin(), v.end()
#define SZ(v) (int) v.size()
#define pb emplace_back
#define ff first
#define ss second

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U>
void debug(T a, U ... b){
	cout << a << " ", debug(b...);
}
template<class T> void pary(T l, T r){
	while(l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) void()
#define pary(...) void()
#endif

template<class A, class B>
ostream& operator<<(ostream& o, pair<A, B> p){
	return o << '(' << p.ff << ',' << p.ss << ')';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, m, K, P;
	cin >> n >> m >> K >> P;
	vector<bool> qua(n);
	vector<ll> tpos(n);
	vector<bool> tfan(n);
	ll total = n;
	for(int i = 0; i < m; i++){
		int c, t;
		cin >> c >> t;
		qua[c - 1] = true;
		tpos[c - 1] = t;
		total += t;
	}
	for(int i = 0; i < K; i++){
		int p;
		cin >> p;
		tfan[p - 1] = true;
		//debug("tfan", p - 1, tfan[p - 1]);
	}
	tpos[0] = 1 + tpos[0];
	for(int i = 1; i < n; i++){
		tpos[i] = tpos[i - 1] + 1 + tpos[i];
	}
	//pary(iter(tpos));

	vector<ll> pos;
	vector<bool> fan;
	for(int i = 0; i < n; i++){
		if(qua[i]) continue;
		pos.pb(tpos[i]);
		fan.pb(tfan[i]);
		//debug("good", i, tpos[i], tfan[i]);
	}
	n = SZ(pos);
	ll off = total - pos.back();
	for(int i = 0; i < n; i++) pos[i] += off;
	//assert(pos.back() == total);
	vector<ll> fanpos;
	for(int i = 0; i < n; i++){
		if(fan[i]){
			fanpos.pb(pos[i]);
		}
	}
	/*pary(iter(pos));
	pary(iter(fan));
	pary(iter(fanpos));*/

	auto solve = [&](const ll p){
		//debug("solve", p);
		vector<vector<int>> f(20, vector<int>(n));
		for(int i = 0; i < n; i++){
			ll nxt;
			if(pos[i] + p < total)
				nxt = *upper_bound(iter(pos), pos[i] + p);
			else
				nxt = *upper_bound(iter(pos), pos[i] + p - total);
			ll fp;
			if(nxt <= fanpos.back()){
				fp = *lower_bound(iter(fanpos), nxt);
			}
			else{
				fp = fanpos[0];
			}

			if(fp + p < total + pos.front())
				f[0][i] = upper_bound(iter(pos), fp + p) - pos.begin() - 1;
			else
				f[0][i] = upper_bound(iter(pos), fp + p - total) - pos.begin() - 1;
		}
		//pary(iter(f[0]));
		vector<vector<ll>> flen(20, vector<ll>(n));
		for(int i = 0; i < n; i++){
			flen[0][i] = i < f[0][i] ? pos[f[0][i]] - pos[i] : pos[f[0][i]] + total - pos[i];
		}
		for(int i = 1; i < 20; i++){
			for(int j = 0; j < n; j++){
				f[i][j] = f[i - 1][f[i - 1][j]];
				flen[i][j] = flen[i - 1][j] + flen[i - 1][f[i - 1][j]];
			}
		}

		for(int i = 0; i < n; i++){
			ll cur = 0;
			int ans = 0;
			int now = i;
			for(int j = 19; j >= 0; j--){
				if(cur + flen[j][now] < total){
					cur += flen[j][now];
					now = f[j][now];
					ans += 1 << j;
				}
			}
			//debug("ok", i, ans);
			ans++;
			if(ans <= P) return true;
		}
		return false;

	};

	ll l = 0, r = total;
	while(l < r){
		ll mid = (l + r) / 2;
		if(solve(mid)) r = mid;
		else l = mid + 1;
	}
	cout << l << "\n";


}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

10 4 3 2
1 2
4 4
6 2
7 5
2 5 8

output:

4

result:

ok single line: '4'

Test #2:

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

input:

8 1 3 5
1 5
4 2 7

output:

0

result:

ok single line: '0'

Test #3:

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

input:

5 2 2 1
1 14
2 14
3 5

output:

1

result:

ok single line: '1'

Test #4:

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

input:

2 1 1 1
1 200000
2

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 344ms
memory: 25048kb

input:

190976 113222 55610 23475
51263 120558
10007 171596
46671 108981
117183 169457
18187 84735
149298 124718
79376 129184
28117 76880
109791 87521
114840 59510
38014 178362
41701 11344
27561 192741
173835 54534
71368 76692
122745 95537
152595 158352
43901 162441
98927 105784
22484 96000
19443 113614
370...

output:

170531

result:

ok single line: '170531'

Test #6:

score: 0
Accepted
time: 603ms
memory: 50120kb

input:

198722 26425 169256 110599
33948 74442
51729 66300
40369 173859
42274 73043
117803 108716
149794 151005
147161 2675
148063 166634
132585 51612
141999 182365
32951 159790
120932 290
82655 150138
49337 10396
171146 129572
33311 193079
195115 171691
180568 77905
65397 110312
156436 149966
9377 55490
12...

output:

1

result:

ok single line: '1'

Test #7:

score: 0
Accepted
time: 208ms
memory: 17960kb

input:

200000 150000 50000 24998
187150 200000
81420 200000
167617 200000
100616 200000
135362 200000
156943 200000
83069 200000
48837 200000
179969 200000
138130 200000
133131 200000
196045 200000
169575 200000
163857 200000
106717 200000
191966 200000
131394 200000
145647 200000
160212 200000
75181 20000...

output:

200002

result:

ok single line: '200002'

Test #8:

score: 0
Accepted
time: 184ms
memory: 17996kb

input:

200000 150000 50000 2
99352 200000
85760 200000
126279 200000
78681 200000
191980 200000
123278 200000
90780 200000
183926 200000
92668 200000
92156 200000
157074 200000
104604 200000
87593 200000
183454 200000
38009 200000
132806 200000
96071 200000
135445 200000
123768 200000
80039 200000
199215 2...

output:

1250012500

result:

ok single line: '1250012500'

Test #9:

score: 0
Accepted
time: 21ms
memory: 4796kb

input:

200000 199999 1 1
44417 200000
47743 200000
134710 200000
118852 200000
9605 200000
150296 200000
80589 200000
3336 200000
66496 200000
90172 200000
190899 200000
3355 200000
107595 200000
111949 200000
146872 200000
72419 200000
115626 200000
127077 200000
173509 200000
194749 200000
109608 200000
...

output:

0

result:

ok single line: '0'

Test #10:

score: -100
Wrong Answer
time: 636ms
memory: 30960kb

input:

200000 100000 100000 25746
186550 200000
85622 200000
21024 200000
59750 200000
76456 200000
87534 200000
76522 200000
103422 200000
165806 200000
138372 200000
166050 200000
176354 200000
15168 200000
69928 200000
187102 200000
130486 200000
182278 200000
161502 200000
95032 200000
119864 200000
17...

output:

10000500004

result:

wrong answer 1st lines differ - expected: '400004', found: '10000500004'