QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#847585 | #9877. Segment Tree | hos_lyric | WA | 28ms | 3948kb | C++14 | 3.0kb | 2025-01-08 07:30:59 | 2025-01-08 07:31:00 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
constexpr Int INF = 1001001001;
int N;
vector<Int> C;
vector<Int> ds;
void pull(int a) {
if (a < 1 << N) {
ds[a] = min(C[a], ds[a << 1] + ds[a << 1 | 1]);
}
}
int main() {
for (; ~scanf("%d", &N); ) {
C.assign(1 << (N+1), INF);
for (int a = 1; a < 1 << (N+1); ++a) {
scanf("%lld", &C[a]);
}
ds = C;
for (int a = 1 << N; --a; ) pull(a);
int Q;
scanf("%d", &Q);
for (int q = 0; q < Q; ++q) {
int O;
scanf("%d", &O);
if (O == 1) {
int J;
Int X;
scanf("%d%lld", &J, &X);
C[J] = X;
for (int a = J; a; a >>= 1) pull(a);
} else if (O == 2) {
int S[2];
scanf("%d%d", &S[0], &S[1]);
Int ans = INF;
// at endpoints of interval as[i]
int as[2];
Int cost[2][2];
for (int i = 0; i < 2; ++i) {
if (S[i] < 1 << N) {
as[i] = (1 << N) + S[i];
cost[i][0] = 0;
cost[i][1] = ds[as[i]];
} else {
as[i] = (1 << (N+1)) - 1;
cost[i][0] = ds[as[i]];
cost[i][1] = 0;
}
}
for (; ; ) {
for (int j = 0; j < 2; ++j) for (int k = 0; k < 2; ++k) {
if (as[0] + j == as[1] + k) {
chmin(ans, cost[0][j] + cost[1][k]);
}
}
if (as[0] == 1) break;
// up
for (int i = 0; i < 2; ++i) {
cost[i][(as[i] ^ 1) & 1] += ds[as[i] ^ 1];
as[i] >>= 1;
chmin(cost[i][1], cost[i][0] + ds[as[i]]);
chmin(cost[i][0], cost[i][1] + ds[as[i]]);
}
}
printf("%lld\n", ans);
} else {
assert(false);
}
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3884kb
input:
3 7 1 14 3 9 4 8 2 6 5 5 13 8 2 3 10 2 0 1 2 0 4 2 4 6 2 4 8 2 3 5 1 6 30 2 3 5 2 4 6 1 1 10000000 2 0 8
output:
2 1 4 8 17 18 13 15
result:
ok 8 tokens
Test #2:
score: -100
Wrong Answer
time: 28ms
memory: 3948kb
input:
1 7914575 2436426 4979445 199989 1 1 6190629 1 1 1407775 1 1 2804784 1 2 2631932 1 1 3078537 1 3 286918 1 2 3238506 1 3 3361868 1 2 9296263 1 3 4836991 1 3 2177068 1 3 4291757 1 1 594328 1 2 8996221 1 1 5531545 1 3 3575467 1 3 3206504 1 1 8344965 1 3 6045895 2 0 2 1 2 6248153 1 1 5797489 1 1 9766466...
output:
7415871 7415871 2624007 2512448 4979445 4979445 4979445 6363152 2436426 4380822 2436426 4979445 2436426 7415871 4979445 2436426 7415871 2808118 2436426 4979445 2436426 7415871 2436426 2436426 7400947 4979445 2436426 7415871 4979445 4979445 4979445 2436426 4979445 2436426 4979445 2436426 4979445 3806...
result:
wrong answer 1st words differ - expected: '8344965', found: '7415871'