QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#69032 | #4583. Concerto de Pandemic | SanguineChameleon | TL | 1704ms | 49728kb | C++20 | 4.8kb | 2022-12-22 17:19:20 | 2022-12-22 17:19:23 |
Judging History
answer
// BEGIN BOILERPLATE CODE
#include <bits/stdc++.h>
using namespace std;
#ifdef KAMIRULEZ
const bool kami_loc = true;
const long long kami_seed = 69420;
#else
const bool kami_loc = false;
const long long kami_seed = chrono::steady_clock::now().time_since_epoch().count();
#endif
const string kami_fi = "kamirulez.inp";
const string kami_fo = "kamirulez.out";
mt19937_64 kami_gen(kami_seed);
long long rand_range(long long rmin, long long rmax) {
uniform_int_distribution<long long> rdist(rmin, rmax);
return rdist(kami_gen);
}
long double rand_real(long double rmin, long double rmax) {
uniform_real_distribution<long double> rdist(rmin, rmax);
return rdist(kami_gen);
}
void file_io(string fi, string fo) {
if (fi != "" && (!kami_loc || fi == kami_fi)) {
freopen(fi.c_str(), "r", stdin);
}
if (fo != "" && (!kami_loc || fo == kami_fo)) {
freopen(fo.c_str(), "w", stdout);
}
}
void set_up() {
if (kami_loc) {
file_io(kami_fi, kami_fo);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
}
void just_do_it();
void just_exec_it() {
if (kami_loc) {
auto pstart = chrono::steady_clock::now();
just_do_it();
auto pend = chrono::steady_clock::now();
long long ptime = chrono::duration_cast<chrono::milliseconds>(pend - pstart).count();
string bar(50, '=');
cout << '\n' << bar << '\n';
cout << "Time: " << ptime << " ms" << '\n';
}
else {
just_do_it();
}
}
int main() {
set_up();
just_exec_it();
return 0;
}
// END BOILERPLATE CODE
// BEGIN MAIN CODE
#define int long long
const int ms = 2e5 + 20;
const int st = 20;
const long long inf = 3e5 + 20;
long long a[ms];
int nxtf[ms];
bool f[ms];
int dr[ms];
int dl[ms];
vector<int> q[ms];
int nxtr[ms];
long long dist[ms][st];
int n, m, k, p;
bool check(long long md) {
dr[n - 1] = 0;
long long cd = 0;
for (int i = 0; i < n; i++) {
int pv = (i + n - 1) % n;
if (dr[pv] == 0) {
dr[i] = 0;
cd = 0;
}
else {
dr[i] = dr[pv] - 1;
cd -= a[i];
cd -= 1;
}
int cc = (i + dr[i]) % n;
while (dr[i] < n - 1) {
cc = (cc + 1) % n;
if (cd + 1 + a[cc] <= md) {
dr[i]++;
cd = cd + 1 + a[cc];
}
else {
break;
}
}
}
cd = 0;
dl[0] = 0;
for (int i = n - 1; i >= 0; i--) {
int pv = (i + 1) % n;
if (dl[pv] == 0) {
dl[i] = 0;
cd = 0;
}
else {
dl[i] = dl[pv] - 1;
cd -= a[i];
cd -= 1;
}
int cc = (i + n - dl[i]) % n;
while (dl[i] < n - 1) {
cc = (cc + n - 1) % n;
if (cd + 1 + a[cc] <= md) {
dl[i]++;
cd = cd + 1 + a[cc];
}
else {
break;
}
}
}
for (int i = 0; i < n; i++) {
q[i].clear();
nxtr[i] = -1;
}
for (int i = 0; i < n; i++) {
if (a[i] > 0) {
continue;
}
if (dl[i] + dr[i] >= n - 1) {
return true;
}
dl[i] = (i + n - dl[i]) % n;
dr[i] = (i + dr[i]) % n;
q[dl[i]].push_back(i);
}
int ff = -1;
for (int k = 0; k < 2; k++) {
for (int i = 0; i < n; i++) {
for (auto x: q[i]) {
if (ff == -1) {
ff = x;
continue;
}
int d1 = (dr[ff] + n - dl[ff]) % n - (i + n - dl[ff]) % n;
int d2 = (dr[x] + n - dl[x]) % n - (i + n - dl[x]) % n;
if (d1 < d2) {
ff = x;
}
}
nxtr[i] = ff;
}
}
for (int i = 0; i < n; i++) {
if (f[i]) {
dist[i][0] = (dr[nxtr[i]] + n - i) % n + 1;
}
}
for (int k = 1; k < st; k++) {
for (int i = 0; i < n; i++) {
if (f[i]) {
int j = (dist[i][k - 1] + i) % n;
dist[i][k] = dist[i][k - 1] + 1 + (nxtf[j] + n - j) % n + dist[nxtf[j]][k - 1] - 1;
}
}
}
for (int i = 0; i < n; i++) {
if (a[i] > 0) {
continue;
}
int mi = n - (dr[i] + n - dl[i]) % n - 1;
int cc = (dr[i] + 1) % n;
long long cd = (nxtf[cc] + n - cc) % n;
cc = nxtf[cc];
int cr = 1;
for (int j = st - 1; j >= 0; j--) {
if (cd + dist[cc][j] <= mi) {
cr += (1 << j);
cd += dist[cc][j];
cc = (dist[cc][j] - 1 + cc) % n;
cc = (cc + 1) % n;
cd += (nxtf[cc] + n - cc) % n;
cc = nxtf[cc];
}
}
if (cd >= mi && cr <= p) {
return true;
}
}
return false;
}
void just_do_it() {
cin >> n >> m >> k >> p;
for (int i = 0; i < m; i++) {
int u, w;
cin >> u >> w;
u--;
a[u] = w;
}
for (int i = 0; i < k; i++) {
int u;
cin >> u;
u--;
f[u] = true;
}
for (int i = 0; i < n; i++) {
if (f[i]) {
nxtf[0] = i;
break;
}
}
for (int i = n - 1; i >= 1; i--) {
if (f[i]) {
nxtf[i] = i;
}
else {
nxtf[i] = nxtf[(i + 1) % n];
}
}
long long lt = 0;
long long rt = inf;
long long res = -1;
while (lt <= rt) {
long long mt = (lt + rt) / 2;
if (check(mt)) {
res = mt;
rt = mt - 1;
}
else {
lt = mt + 1;
}
}
cout << res;
}
// END MAIN CODE
詳細信息
Test #1:
score: 100
Accepted
time: 6ms
memory: 15784kb
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: 6ms
memory: 15792kb
input:
8 1 3 5 1 5 4 2 7
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 4ms
memory: 15712kb
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: 17696kb
input:
2 1 1 1 1 200000 2
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 1704ms
memory: 49728kb
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: -100
Time Limit Exceeded
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...