QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#72961#4583. Concerto de PandemicpauloamedWA 1085ms60408kbC++176.0kb2023-01-21 04:34:322023-01-21 04:34:36

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-21 04:34:36]
  • 评测
  • 测评结果:WA
  • 用时:1085ms
  • 内存:60408kb
  • [2023-01-21 04:34:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long

const int MAXN = 200010;

vector<int> fans;
vector<pair<int,int>> v[MAXN];

vector<int> pos;

namespace cactus{
	vector<vector<int>> get_cycles(int* to, int n){
		queue<int> q;
 
		vector<int> indeg(n, 0);
		for(int i = 0; i < n; ++i) indeg[to[i]]++;
		for(int i = 0; i < n; ++i) if(indeg[i] == 0)
			q.push(i);
 
		while(q.size()){
			int x = q.front(); q.pop();
			if(--indeg[to[x]] == 0)
				q.push(to[x]);
		}
 
		vector<vector<int>> cycles;
		for(int i = 0; i < n; ++i) if(indeg[i] == 1){
			vector<int> cycle;
			int x = to[i];
			while(true){
				cycle.push_back(x);
				indeg[x] = 0;
				if(x == i) break;
				x = to[x];
			}
			cycles.push_back(cycle);
		}
		return cycles;
	}
}

namespace circular_arc{
bool between(int l, int r, int x){
  if(l > r) return (x >= l || x <= r);
  else return (x >= l && x <= r);
}
 
bool intersect(pair<int,int> &a, pair<int,int> &b){
	return (between(a.first, a.second, b.first) || between(a.first, a.second, b.second) || 
		between(b.first, b.second, a.first) || between(b.first, b.second, a.second));
}
 
struct Point{
	int x, arc_id;
	bool is_l;
	bool operator<(const Point &b) const{
		if(x == b.x) return is_l > b.is_l;
		else return x < b.x;
	}
};
 
vector<pair<int,int>> v;
vector<int> gd; // last one is not in GD

Point pts[2 * MAXN];
int next[MAXN];
bool is_open[MAXN];
int n;
int time_vis[MAXN][2];
 
void compute_next(){
	memset(is_open, 0, sizeof(bool) * n);
	for(int i = 0; i < n; ++i){
		time_vis[i][0] = time_vis[i][1] = next[i] = -1;
	}
 
	queue<int> closed;
	for(int i = 0; i < 6 * n; ++i){
		int j = i % (2 * n);
		auto [p, arc_id, is_l] = pts[j];
 
		if(is_l){ // is L
			time_vis[arc_id][0] = i;
			is_open[arc_id] = 1;
		}else if(is_open[arc_id]){ // is R and already openned
			time_vis[arc_id][1] = i;
			is_open[arc_id] = 0;
			while(closed.size()){
				if(closed.front() != arc_id){
					if(time_vis[arc_id][0] < time_vis[closed.front()][1]) 
						break;
				}
				next[closed.front()] = arc_id;
				closed.pop();
			}
			if(next[arc_id] == -1)
				closed.push(arc_id);
		}
	}
}
 
void compute_gd(const vector<int> &cycle){
	gd.clear();
	int i = cycle[0];
	gd.push_back(i);
	for(int j = 1; j < cycle.size(); ++j){
		gd.push_back(cycle[j]);
		if(intersect(v[i], v[cycle[j]])) break;
	}
}

void built_pts(int MAX_COORD){
	if(true){ // v sorted
	
	auto norm = [&](int x){ return (x + MAX_COORD) % MAX_COORD; };
	for(int i = 0; i < n; ++i){
		pts[i] = {v[i].first, i, 1};
		pts[i + n] = {v[i].second, i, 0};
	}
	for(auto &[l, r] : v) l = norm(l), r = norm(r);	

	inplace_merge(pts, pts + n, pts + 2 * n);
	int m = lower_bound(pts, pts + 2 * n, MAX_COORD, [](Point &p, int x){
		return p.x < x;
	}) - pts;
	for(int i = 0; i < 2 * n; ++i) pts[i].x = norm(pts[i].x);
	inplace_merge(pts, pts + n, pts + 2 * n);

	return;
	}

	// v not sorted
	for(int i = 0; i < n; ++i){
		pts[2 * i] = {v[i].first, i, 1};
		pts[2 * i + 1] = {v[i].second, i, 0};
	}

	sort(pts, pts + 2 * n, [](Point &a, Point &b){
		if(a.x == b.x) return a.is_l > b.is_l;
		else return a.x < b.x;
	});
}
 
int get_min_clique(const vector<pair<int,int>> &_v, int MAX_COORD = MAXN){
	v = _v;
	n = v.size();
	if(n == 0) return 0;
	 
	built_pts(MAX_COORD);
	compute_next();
	auto cycles = cactus::get_cycles(next, n);
 
	compute_gd(cycles[0]);
 
	if(gd.size() == 1) return 1;
	if(gd.front() == gd.back()) return gd.size() - 1;
	else return gd.size();
}
}

vector<int> fanid;

bool solve(int will_walk, int p){
  int n = pos.size() / 2;

  vector<pair<int,int>> intervs;

	int curr_r = 0, curr_l = 0;
  for(auto i : fanid){
		// andar r enquanto menor que nxt_pos
		int nxt_pos_r = pos[i] + will_walk;
		while(curr_r < pos.size() && pos[curr_r] <= nxt_pos_r)
			curr_r++;

		// andar l enquanto menor que pos
		int nxt_pos_l = pos[i + n] - will_walk;
		while(curr_l < pos.size() && pos[curr_l] < nxt_pos_l)
			curr_l++;

		int dist_l = i + n - curr_l;
		int dist_r = curr_r - i;
    if(dist_l + dist_r >= n) continue;

    // intervs.push_back({curr_l, curr_r - 1 });
    intervs.push_back({curr_l, curr_r - 1});
  }

	vector<int> x[2];
	for(auto [l, r] : intervs){
		x[0].push_back(l);
		x[1].push_back(r);
	}
	for(int j = 0; j < 2; ++j){
		vector<int> u = x[j];
		sort(u.begin(), u.end());
		assert(u == x[j]);
	}

  int needed = circular_arc::get_min_clique(intervs, n);
  return needed <= p;
}

int32_t main(){
  cin.tie(NULL)->sync_with_stdio(false);
  int n, m, k, p; cin >> n >> m >> k >> p;
  
  vector<int> c(n, 0);
  for(int i = 0; i < m; ++i){
    int j, t; cin >> j >> t; j--;
    c[j] = t;
  }

  for(int i = 0; i < k; ++i){
    int x; cin >> x; x--;
    fans.push_back(x);
  }
	sort(fans.begin(), fans.end());

  vector<int> good;
  for(int i = 0; i < n; ++i) if(c[i] == 0){
    good.push_back(i);
  }

  if(good.size() == 1){
    cout << 0 << "\n";
    return 0;
  }

  auto id = [&](int x){
    return (int) (lower_bound(good.begin(), good.end(), x) - good.begin());
  };

  for(auto x : fans) fanid.push_back(id(x));

  for(int i = 0; i < n; ++i) if(c[i] == 0){
		// i nao tem quarentena

    int l = (i - 1 + n) % n;
    int r = (i + 1) % n;
    int cost_l = 1, cost_r = 1;
    
    while(c[l] != 0){
      cost_l += c[l] + 1;
      l = (l - 1 + n) % n;
    }

    while(c[r] != 0){
      cost_r += c[r] + 1;
      r = (r + 1) % n;
    }

    v[id(i)].push_back({id(l), cost_l});
    v[id(i)].push_back({id(r), cost_r});
  }

  int curr_pos = 0;
  for(int i = 0; i < 2 * good.size(); ++i){
    pos.push_back(curr_pos);
    curr_pos += v[i % good.size()][1].second;
  }

  int tot = pos[good.size()];

  if(solve(0, p)){
    cout << 0 << "\n";
  }else{
    int ans = 0;
    int pot = (1LL << 36);
    while(pot){
      int mans = ans + pot;
      if(mans < tot && !solve(mans, p)){
        ans = mans;
      }
      pot /= 2;
    }
    cout << ans + 1 << "\n";
  }

}

詳細信息

Test #1:

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

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: 3ms
memory: 12248kb

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: 12884kb

input:

5 2 2 1
1 14
2 14
3 5

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 3ms
memory: 9940kb

input:

2 1 1 1
1 200000
2

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 440ms
memory: 29116kb

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: 1085ms
memory: 60408kb

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: 335ms
memory: 27276kb

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: 307ms
memory: 29420kb

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: 38ms
memory: 9692kb

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: 0
Accepted
time: 636ms
memory: 40820kb

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:

400004

result:

ok single line: '400004'

Test #11:

score: 0
Accepted
time: 42ms
memory: 12376kb

input:

200000 199990 10 9
185044 200000
96615 200000
172973 200000
82849 200000
162889 200000
59668 200000
20522 200000
193263 200000
70559 200000
140931 200000
147680 200000
26312 200000
133330 200000
74332 200000
149589 200000
61277 200000
173461 200000
152403 200000
174666 200000
56706 200000
9288 20000...

output:

3865019326

result:

ok single line: '3865019326'

Test #12:

score: 0
Accepted
time: 35ms
memory: 14420kb

input:

200000 199998 2 1
67932 200000
165398 200000
653 200000
12879 200000
179014 200000
173052 200000
19237 200000
31754 200000
83892 200000
67089 200000
172429 200000
20736 200000
19809 200000
195941 200000
165861 200000
192485 200000
50670 200000
154401 200000
183669 200000
160442 200000
96158 200000
4...

output:

19999900000

result:

ok single line: '19999900000'

Test #13:

score: 0
Accepted
time: 300ms
memory: 26360kb

input:

200000 150000 50000 14589
9852 200000
146233 200000
81635 200000
153688 200000
180401 200000
131217 200000
147689 200000
175789 200000
157008 200000
82379 200000
197870 200000
158300 200000
136907 200000
90916 200000
133283 200000
115911 200000
178151 200000
52380 200000
125603 200000
17720 200000
5...

output:

400004

result:

ok single line: '400004'

Test #14:

score: 0
Accepted
time: 334ms
memory: 26864kb

input:

200000 150000 50000 3
92863 200000
143656 200000
177807 200000
82115 200000
127226 200000
153355 200000
195151 200000
183196 200000
56488 200000
105395 200000
174745 200000
9192 200000
122947 200000
102569 200000
71127 200000
198334 200000
140867 200000
91775 200000
176858 200000
78928 200000
116317...

output:

1666816667

result:

ok single line: '1666816667'

Test #15:

score: 0
Accepted
time: 5ms
memory: 12352kb

input:

10 2 2 4
1 45
9 45
5 6

output:

0

result:

ok single line: '0'

Test #16:

score: 0
Accepted
time: 263ms
memory: 20176kb

input:

184056 156924 27132 5487
31071 76922
182522 95921
153369 55991
171710 52252
41681 88855
80541 147855
17375 23664
166681 99712
85334 139650
91006 107711
183992 133132
18219 116694
10973 36327
29655 3541
9566 121602
20135 150626
165572 199426
34139 114077
172106 9046
111675 183349
52859 2653
162895 48...

output:

1391357

result:

ok single line: '1391357'

Test #17:

score: 0
Accepted
time: 879ms
memory: 43764kb

input:

198946 85509 113437 16454
55928 11746
151106 176741
67787 119235
6964 121879
87064 105123
182446 67770
148232 164626
84669 181152
177124 116910
124895 83907
65566 65423
153714 197476
67769 108011
8201 139194
91192 80237
84858 168819
73079 185222
55701 151129
60694 17931
179882 117777
154826 119669
1...

output:

251741

result:

ok single line: '251741'

Test #18:

score: 0
Accepted
time: 36ms
memory: 11200kb

input:

184845 184844 1 1
159765 128047
129626 3304
35698 88302
142782 113626
46033 196503
94300 101851
148700 52627
101827 122109
34448 104944
94260 154823
32130 48872
72954 199176
50529 151953
53369 38890
35837 195530
107050 68183
105336 41797
127928 74999
144029 51097
16189 75339
119777 179826
94102 1624...

output:

0

result:

ok single line: '0'

Test #19:

score: 0
Accepted
time: 35ms
memory: 10804kb

input:

183091 183090 1 1
12308 23858
135357 5256
150368 37499
118187 37965
54415 24892
125817 38590
81315 186626
13463 164488
136540 24565
145451 98230
130596 163280
80257 160167
131667 188684
43557 68858
77488 104306
25073 144258
104735 157480
23991 28887
67302 68251
127993 120450
93683 52143
127786 13219...

output:

0

result:

ok single line: '0'

Test #20:

score: 0
Accepted
time: 39ms
memory: 14612kb

input:

185561 185559 2 1
97801 136363
66008 136066
173944 59291
84394 162605
136281 88025
155011 701
184637 86732
87309 98378
70530 162334
162566 153674
158032 185895
127014 172074
65742 28387
102936 28533
84549 125060
652 51442
70185 182692
1996 112759
101772 21021
34755 15804
92317 146543
97125 153712
13...

output:

1579892162

result:

ok single line: '1579892162'

Test #21:

score: 0
Accepted
time: 34ms
memory: 13384kb

input:

183182 183180 2 1
63223 3168
141520 69479
102948 133687
168811 61676
1040 131270
96738 46087
44583 80530
34917 198354
143916 73083
90118 136430
143264 19353
102753 197144
4376 71023
132710 140871
61456 141299
39456 46272
36213 130567
156330 173816
154675 195443
14550 106176
147487 91753
77544 28222
...

output:

7692313709

result:

ok single line: '7692313709'

Test #22:

score: 0
Accepted
time: 48ms
memory: 15384kb

input:

195431 195367 64 30
36156 60535
180283 153306
192146 194701
124139 127831
76060 17748
148550 69471
69448 1188
179162 186722
188498 44999
11250 67523
27826 144158
191515 18496
127589 12954
127966 24839
9285 26855
110964 28073
167740 98491
65303 92934
162830 75852
64299 156312
61352 100260
172221 7723...

output:

287022566

result:

ok single line: '287022566'

Test #23:

score: 0
Accepted
time: 30ms
memory: 14884kb

input:

195507 195443 64 28
107028 104100
106907 193032
45258 195130
168641 198440
90592 198719
31617 88887
72796 79245
41191 20722
53917 159740
34173 21748
127611 171540
186506 92330
189538 141942
41574 122048
69615 93751
59046 89045
176461 111632
74703 8471
5065 42899
1888 179533
150575 88597
72116 37233
...

output:

302878794

result:

ok single line: '302878794'

Test #24:

score: -100
Wrong Answer
time: 42ms
memory: 15152kb

input:

184543 183830 713 203
108924 161080
101919 104871
50685 182714
52699 74184
180944 142023
55277 4859
4461 153623
141162 149967
8865 72164
148155 80178
10817 75920
2978 41235
7205 55147
13738 2734
171075 142707
115453 95060
31261 172373
86949 71831
32714 5579
53948 168389
485 99005
121956 131933
11897...

output:

29012329

result:

wrong answer 1st lines differ - expected: '42317159', found: '29012329'