QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#549922 | #5669. Traveling in Jade City | Tiga_Pilot_2# | WA | 2546ms | 42384kb | C++20 | 5.9kb | 2024-09-06 23:29:40 | 2024-09-06 23:29:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(a, b) for (int i = (int) a; i < (int) b; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int mxn = 2e6;
const int inf = 1e9;
vector<int> t(mxn*4);
vector<int> a(mxn);
int n, k, m, q, sz;
int combine(int x, int y) {
if(x >= inf || y >= inf) {
return inf;
} else {
if(x >= inf-y) {
return inf;
} else {
return x+y;
}
}
}
void build(int v, int tl, int tr) {
if (tl == tr) {
t[v] = a[tl];
} else {
int tm = (tl + tr) / 2;
build(v*2, tl, tm);
build(v*2+1, tm+1, tr);
t[v] = combine(t[v*2], t[v*2+1]);
}
}
void update(int v, int tl, int tr, int pos, int new_val) {
if (tl == tr) {
t[v] = new_val;
} else {
int tm = (tl + tr) / 2;
if (pos <= tm)
update(v*2, tl, tm, pos, new_val);
else
update(v*2+1, tm+1, tr, pos, new_val);
t[v] = combine(t[v*2], t[v*2+1]);
}
}
int query(int v, int tl, int tr, int l, int r) {
if (l > r)
return 0;
if (l == tl && r == tr)
return t[v];
int tm = (tl + tr) / 2;
return combine(query(v*2, tl, tm, l, min(r, tm)),
query(v*2+1, tm+1, tr, max(l, tm+1), r));
}
array<int, 6> sol(int u, int kiri, int tengah, int kanan) {
array<int, 6> res = {inf, inf, inf, inf, inf, inf};
int atas, bawah;
if(u <= k) {
atas = query(1, 0, sz-1, 0, u-2);
bawah = query(1, 0, sz-1, u-1, k-2);
res[1] = combine(atas, kiri);
res[2] = combine(atas, tengah);
res[4] = combine(bawah, kiri);
res[5] = combine(bawah, tengah);
} else if(u <= n) {
atas = query(1, 0, sz-1, u-1, n-1);
bawah = query(1, 0, sz-1, k-1, u-2);
res[1] = combine(atas, kanan);
res[2] = combine(atas, tengah);
res[4] = combine(bawah, kanan);
res[5] = combine(bawah, tengah);
} else {
atas = query(1, 0, sz-1, n, u-1);
bawah = query(1, 0, sz-1, u, sz-1);
res[1] = combine(atas, kiri);
res[2] = combine(atas, kanan);
res[4] = combine(bawah, kiri);
res[5] = combine(bawah, kanan);
}
res[0] = bawah;
res[3] = atas;
return res;
}
// array<int, 3> sol2(int u, int kiri, int tengah, int kanan) {
// array<int, 3> res = {inf, inf, inf};
// if(u <= k) {
// int atas = query(1, 0, sz-1, 0, u-2);
// int bawah = query(1, 0, sz-1, u-1, k-2);
// res[0] = bawah;
// res[1] = atas + kiri;
// res[2] = atas + tengah;
// } else if(u <= n) {
// int atas = query(1, 0, sz-1, u-1, n-1);
// int bawah = query(1, 0, sz-1, k-1, u-2);
// res[0] = bawah;
// res[1] = atas + kanan;
// res[2] = atas + tengah;
// } else {
// int atas = query(1, 0, sz-1, n, u-1);
// int bawah = query(1, 0, sz-1, u, sz-1);
// res[0] = bawah;
// res[1] = atas + kiri;
// res[2] = atas + kanan;
// }
// return res;
// }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k >> m >> q;
sz = n+m+1;
for(int i=0; i<n; i++) {
cin >> a[i];
}
for(int i=n; i<=n+m; i++) {
cin >> a[i];
}
// for(int i=0; )
build(1, 0, sz-1);
while(q--) {
char ct;
cin >> ct;
if(ct == 'q') {
// for(int i=0; i<sz; i++){
// cout << query(1, 0, sz-1, i, i) << " \n"[i==sz-1];
// }
int u, v;
cin >> u >> v;
if(u == v) {
cout << 0 << "\n";
} else {
if(u > v) {
swap(u, v);
}
int ans;
if(u >= n) {
ans = query(1, 0, sz-1, u, v-1);
}
else if(v >= n) {
ans = query(1, 0, sz-1, u-1, v-1);
} else {
ans = query(1, 0, sz-1, u-1, v-2);
}
int kiri = query(1, 0, sz-1, k-1, n-1);
int tengah = query(1, 0, sz-1, n, sz-1);
int kanan = query(1, 0, sz-1, 0, k-2);
// cout << kiri << " " << tengah << " " << kanan << "\n";
array<int, 6> ax1 = sol(u, kiri, tengah, kanan);
array<int, 6> ax2 = sol(v, kiri, tengah, kanan);
for(int i=0; i<3; i++) {
// cout << ax1[i] << " \n"[i==2];
for(int j=0; j<3; j++) {
int as = combine(ax1[i], ax2[j]);
ans = min(ans, as);
}
}
for(int i=3; i<6; i++) {
for(int j=3; j<6; j++) {
int as = combine(ax1[i], ax2[j]);
ans = min(ans, as);
}
}
if(ans >= inf) {
cout << "impossible\n";
} else {
cout << ans << "\n";
}
}
} else {
int x;
cin >> x;
if(ct == 'x') {
x = x+n+1;
}
int qry = query(1, 0, sz-1, x-1, x-1);
if(qry >= inf) {
update(1, 0, sz-1, x-1, a[x-1]);
} else {
update(1, 0, sz-1, x-1, inf);
}
}
// for(int i=0; i<sz; i++){
// cout << query(1, 0, sz-1, i, i) << " \n"[i==sz-1];
// }
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 42204kb
input:
4 3 1 9 2 3 8 4 1 1 q 3 4 x 0 q 3 4 c 3 q 3 4 c 1 q 3 4 x 0 q 3 4
output:
6 8 9 impossible 6
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 42340kb
input:
4 3 1 9 2 3 8 4 1 1 q 3 4 x 0 q 3 4 c 3 q 3 4 c 1 q 3 4 x 0 q 3 4
output:
6 8 9 impossible 6
result:
ok 5 lines
Test #3:
score: 0
Accepted
time: 1454ms
memory: 42184kb
input:
1000000 999999 1000000 1000000 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 2...
output:
177406400 122264600 70328400 impossible impossible impossible impossible impossible impossible impossible impossible impossible 29295200 impossible 22163200 impossible impossible impossible 11422200 impossible 62579800 impossible 35339400 impossible 20157200 impossible impossible impossible impossib...
result:
ok 500003 lines
Test #4:
score: 0
Accepted
time: 1193ms
memory: 42200kb
input:
100000 25123 500000 1000000 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 ...
output:
4243800 37968200 35427000 52078200 5074200 70821200 13901400 13614600 8774800 68958800 49822200 31077400 impossible 45392400 48946000 76885400 37532600 34416200 impossible 20744200 71652000 21288000 7501600 70315400 14721800 impossible 12981800 81039600 9506800 impossible 33487200 53520200 impossibl...
result:
ok 500004 lines
Test #5:
score: 0
Accepted
time: 1547ms
memory: 42208kb
input:
1000000 543210 999999 1000000 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 20...
output:
43962400 803800 153423600 impossible impossible impossible impossible impossible 191566200 impossible impossible impossible impossible 84524200 impossible 8790000 impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible 86439200 20798400 impossibl...
result:
ok 666666 lines
Test #6:
score: 0
Accepted
time: 1915ms
memory: 42336kb
input:
999999 2 1000000 1000000 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200...
output:
103577000 40419800 44334400 117613400 27695600 101675800 93767600 impossible impossible 41683400 58145400 impossible impossible 38841000 impossible impossible 60723200 impossible impossible impossible 35102200 360200 impossible 64912000 48484000 impossible impossible impossible impossible impossible...
result:
ok 666666 lines
Test #7:
score: 0
Accepted
time: 1520ms
memory: 42192kb
input:
10 5 1000000 1000000 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200...
output:
94819200 65730000 72994800 49117800 104138800 186947800 44801800 49390200 165897000 78473600 43124000 7660200 impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible imp...
result:
ok 666666 lines
Test #8:
score: 0
Accepted
time: 1857ms
memory: 42384kb
input:
1000000 371220 10 1000000 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 20...
output:
20563800 35454600 impossible impossible impossible 787600 impossible 34108400 impossible impossible impossible 18207600 impossible impossible impossible 55803600 impossible impossible 2024800 impossible impossible impossible impossible impossible impossible impossible impossible impossible impossibl...
result:
ok 833321 lines
Test #9:
score: -100
Wrong Answer
time: 2546ms
memory: 42204kb
input:
1000000 543210 1000000 1000000 55 172 71 52 118 20 70 172 64 49 84 89 145 22 84 186 131 52 18 28 59 73 88 52 82 11 75 157 71 55 184 129 87 109 153 139 121 184 37 96 123 102 186 99 191 116 28 45 198 166 103 164 171 149 66 193 65 110 191 123 51 138 100 146 139 129 168 127 125 55 178 27 80 87 101 21 13...
output:
30670961 48913371 7774973 27843322 64930666 19787521 32236183 33937440 21950724 29313510 69061178 48818521 12208541 65243879 41433227 67580303 14884583 56319432 47932125 69665033 29946609 71525011 9854513 34362272 26512727 21612559 10235684 36689531 31170755 61421169 9720654 34948295 29798373 623856...
result:
wrong answer 720059th lines differ - expected: '11730009', found: '11729939'