QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#549021 | #5669. Traveling in Jade City | skrghariapa# | WA | 738ms | 68992kb | C++20 | 6.9kb | 2024-09-06 00:30:06 | 2024-09-06 00:30:07 |
Judging History
answer
#include <bits/stdc++.h>
#include <bit>
#include <bitset>
#include <cstdint>
#include <iostream>
using namespace std;
// t2
#define gc getchar_unlocked
#define pii pair<long long, long long>
using ll = long long;
using cd = complex<double>;
const ll maxN = 1e6 + 10, maxM = 2e5 + 10, MAX = 2e6 + 10;
//const ll maxScore = 4294967295;
const ll mod = 1e9 + 7;
const double pi = acos(-1.0);
const double PI = acos(-1.0);
const double e = exp(1.0);
const ll naught = -100001;
const ll maxT = ceil(sqrt(maxN)) + 1;
const ll root_rec = 15311432;
const ll root_1 = 469870224;
const ll root_pw = (1 << 23);
const int K = 20;
const int g = 3;
const int LOGN = 20;
const int num1 = 16;
const int INF = 1e9;
//const ll is_query = -(1LL<<62)
ll seg[maxN * 4][2];
ll pref[maxN], prefL[maxN], n, m, k;
ll ril[maxN][2];
template <typename T> void fastInt(T& angka) {
T kali = 1; angka = 0; char input = gc();
while (!isdigit(input)) { if (input == '-') kali = -1; input = gc(); }
while (isdigit(input)) angka = (angka << 3) + (angka << 1) + input - 48, input = gc();
angka *= kali;
}
void fastStr(string& str) {
str = "";
char c = '0';
while ((c = gc()) && (c != -1 && c != '\n' && c != '\t' && c != '\r' && c != ' ')) {
str += c;
}
}
ll powMod(ll x, ll y, ll p){
ll res = 1;
x %= p;
if(!x) return 0;
while (y > 0){
if (y & 1) res = ((res % p) * (x % p)) % p;
y = y >> 1;
x = ((x % p) * (x % p)) % p;
}
return res % p;
}
ll inverseMod(ll x, ll p){
return powMod(x, p - 2, p);
}
void upd(ll ind, ll l, ll r, ll i, ll j){
if(r < i || i < l) return;
if(l == r){
assert(l == i);
ril[l][j] ^= 1;
seg[ind][j] = ril[l][j];
return;
}
ll mid = (l + r) >> 1;
upd(ind << 1, l, mid, i, j);
upd(ind << 1 | 1, mid + 1, r, i, j);
seg[ind][j] = seg[ind << 1][j] + seg[ind << 1 | 1][j];
}
ll query(ll ind, ll l, ll r, ll tl, ll tr, ll j){
if(r < tl || tr < l) return 0;
if(tl <= l && r <= tr) return seg[ind][j];
ll mid = (l + r) >> 1;
return query(ind << 1, l, mid, tl, tr, j) + query(ind << 1 | 1, mid + 1, r, tl, tr, j);
}
ll consider(ll x, ll y){
if(x == -1) return y;
if(y == -1) return x;
return min(x, y);
}
ll clockwise(ll t1, ll t2){
if(t1 == t2) return 0;
ll asli = pref[max(t1, t2) - 1] - pref[min(t1, t2) - 1];
if(t2 < t1){
ll u = seg[1][0] - query(1, 1, n, t2, t1, 0);
if(u == 0){
return pref[n] - asli;
}else{
return -1;
}
}else{
ll u = query(1, 1, n, t1, t2, 0);
if(u == 0){
return asli;
}else{
return -1;
}
}
}
ll counterclock(ll t1, ll t2){
if(t1 == t2) return 0;
return clockwise(t2, t1);
//ll asli = pref[max(t1, t2) - 1] - pref[min(t1, t2) - 1];
/*
if(t2 < t1){
ll k = t2 - 1;
ll u = seg[1][0] - query(1, 1, n, t1, k, 0);
if(u == 0){
return pref[n] - pref[t1 - 1] + pref[k];
}else{
return -1;
}
}else{
ll k = t1 - 1;
if(k == 0) k = n;
ll u = query(1, 1, n, t2, k, 0);
if(u == 0){
cout << t1 << "w " << t2 << endl;
return pref[t2 - 1] - pref[k];
}else{
return -1;
}
}*/
}
ll case1(ll t1, ll t2){
ll ans = -1;
// clockwise
ans = consider(ans, clockwise(t1, t2));
//cout << "ans1: " << ans << endl;
ans = consider(ans, counterclock(t1, t2));
//cout << "ans2: " << ans << endl;
if(seg[1][1] == 0){
ll c1 = clockwise(t1, 1);
ll cc1 = counterclock(t1, 1);
ll k1 = consider(c1, cc1);
ll c2 = clockwise(t1, k);
ll cc2 = counterclock(t1, k);
ll k2 = consider(c2, cc2);
ll c3 = clockwise(1, t2);
ll cc3 = counterclock(1, t2);
ll k3 = consider(c3, cc3);
ll c4 = clockwise(k, t2);
ll cc4 = counterclock(k, t2);
ll k4 = consider(c4, cc4);
//cout << k1 << " " << k2 << " " << k3 << " " << k4 << " " << c3 << " " << cc3 << endl;
if(k1 != -1 && k4 != -1) ans = consider(ans, k1 + k4 + prefL[m + 1]);
if(k2 != -1 && k3 != -1) ans = consider(ans, k2 + k3 + prefL[m + 1]);
}
return ans;
}
ll case2(ll t1, ll t2){
ll u1 = clockwise(t1, k);
ll u2 = counterclock(t1, k);
ll ans = -1;
ll k1 = consider(u1, u2);
if(k1 != -1 && query(1, 1, m + 1, t2 - n + 1, m + 1, 1) == 0){
ans = consider(k1 + prefL[m + 1] - prefL[t2 - n], ans);
}
ll u3 = clockwise(t1, 1);
ll u4 = counterclock(t1, 1);
ll k2 = consider(u3, u4);
if(k2 != -1 && query(1, 1, m + 1, 1, t2 - n, 1) == 0){
ans = consider(k2 + prefL[t2 - n], ans);
}
return ans;
}
ll case3(ll t1, ll t2){
return case2(t2, t1);
}
ll case4(ll t1, ll t2){
if(t2 > t1) swap(t1, t2);
ll u1 = clockwise(1, k);
ll u2 = counterclock(1, k);
ll k1 = consider(u1, u2);
ll ans = -1;
if(k1 != -1 && query(1, 1, m + 1, 1, t1 - n, 1) == 0 && query(1, 1, m + 1, t2 - n + 1, m + 1, 1) == 0){
ans = consider(ans, k1 + prefL[t1 - n] + pref[m + 1] - pref[t2 - n]);
}
if(query(1, 1, m + 1, t1 - n + 1, t2 - n, 1) == 0){
ans = consider(ans, prefL[t2 - n] - pref[t1 - n]);
}
return ans;
}
void solve(){
ll q;
fastInt(n); fastInt(k); fastInt(m); fastInt(q);
for(int i = 1; i <= n; i++){
ll x; fastInt(x);
pref[i] = pref[i - 1] + x;
}
for(int i = 1; i <= m + 1; i++){
ll x; fastInt(x);
prefL[i] = prefL[i - 1] + x;
}
for(int i = 1; i <= q; i++){
string s1; fastStr(s1);
if(s1 == "c"){
ll t; fastInt(t);
upd(1, 1, n, t, 0);
}else if(s1 == "x"){
ll t; fastInt(t);
t++;
upd(1, 1, m + 1, t, 1);
}else{
ll t1, t2;
fastInt(t1); fastInt(t2);
ll u = -1;
if(1 <= t1 && t1 <= n && 1 <= t2 && t2 <= n){
u = case1(t1, t2);
}else if(1 <= t1 && t1 <= n && n < t2 <= n + m){
u = case2(t1, t2);
}else if(n < t1 <= n + m && 1 <= t2 <= n){
u = case3(t1, t2);
}else{
u = case4(t1, t2);
}
if(u == -1) cout << "impossible" << '\n';
else cout << u << '\n';
}
}
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.precision(10);
//auto beg = high_resolution_clock::now();
//cout << req(1e7 + 8) << '\n';
//precalc();
int t; t = 1;
while(t--) solve();
//auto en = high_resolution_clock::now();
//auto dur = duration_cast<microseconds>(en - beg);
//cout << dur.count() << endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5724kb
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: 1ms
memory: 5852kb
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: -100
Wrong Answer
time: 738ms
memory: 68992kb
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 -62151400 impossible -102674400 impossible -11303400 impossible -141187200 impossible impossible impossible im...
result:
wrong answer 19th lines differ - expected: '11422200', found: '-62151400'