QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#115777 | #6630. Triangle Collection | hos_lyric | 0 | 2ms | 3752kb | C++14 | 4.1kb | 2023-06-27 03:11:57 | 2023-06-27 03:12: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 <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; }
int N, Q;
vector<Int> C;
Int brute() {
auto check = [&](Int tar) -> bool {
vector<Int> one(N + 1), two(N + 1);
{
Int lot = tar;
for (int i = N; i >= 1; --i) {
const Int t = min(C[i] / 2, lot);
lot -= t;
one[i] = C[i] - 2 * t;
two[i] = t;
}
}
int i = 1;
for (int j = 1; j <= N; ++j) {
for (; two[j] > 0; ) {
const int limI = min(2 * j - 1, N);
if (i > limI) {
return false;
} else if (one[i] == 0) {
++i;
} else {
const Int t = min(one[i], two[j]);
one[i] -= t;
two[j] -= t;
}
}
}
return true;
};
Int lo = 0, hi = 0;
for (int i = 1; i <= N; ++i) {
hi += C[i] / 2;
}
hi += 1;
for (; lo + 1 < hi; ) {
const Int mid = (lo + hi) / 2;
(check(mid) ? lo : hi) = mid;
}
// cerr<<"brute "<<C<<" = "<<lo<<endl;
return lo;
}
Int slow() {
Int sumTwo = 0;
vector<Int> fs(N + 1, 0);
for (int i = 1; i <= N; ++i) {
const Int one = C[i] % 2;
const Int two = C[i] / 2;
sumTwo += two;
fs[i] += one;
fs[min(2 * i - 1, N)] -= two;
}
Int mn = 0;
Int now = 0;
for (int i = 1; i <= N; ++i) {
now += fs[i];
chmin(mn, now);
}
Int ans = sumTwo;
// 2 -> 1,1
ans -= (-mn + 2) / 3;
return ans;
}
struct Data {
Int sum, mn;
Data(Int val = 0) : sum(val), mn(min(val, 0LL)) {}
void pull(const Data &l, const Data &r) {
sum = l.sum + r.sum;
mn = min(l.mn, l.sum + r.mn);
}
};
int main() {
for (; ~scanf("%d%d", &N, &Q); ) {
C.assign(N + 1, 0);
for (int i = 1; i <= N; ++i) {
scanf("%lld", &C[i]);
}
Int sumTwo = 0;
vector<Int> fs(N + 1, 0);
auto add = [&](int i, int sig) -> void {
const Int one = C[i] % 2;
const Int two = C[i] / 2;
sumTwo += sig * two;
fs[i] += sig * one;
fs[min(2 * i - 1, N)] -= sig * two;
};
for (int i = 1; i <= N; ++i) {
add(i, +1);
}
int segN;
for (segN = 1; segN < N + 1; segN <<= 1) {}
vector<Data> seg(segN << 1);
for (int i = 0; i < N; ++i) {
seg[segN + i] = Data(fs[i]);
}
for (int u = segN; --u; ) {
seg[u].pull(seg[u << 1], seg[u << 1 | 1]);
}
auto update = [&](int i) -> void {
int u = segN + i;
seg[u] = Data(fs[i]);
for (; u >>= 1; ) {
seg[u].pull(seg[u << 1], seg[u << 1 | 1]);
}
};
for (int q = 0; q < Q; ++q) {
int L;
Int D;
scanf("%d%lld", &L, &D);
add(L, -1);
C[L] += D;
add(L, +1);
update(L);
update(min(2 * L - 1, N));
Int ans = sumTwo;
ans -= (-seg[1].mn + 2) / 3;
printf("%lld\n", ans);
#ifdef LOCAL
const Int brt=brute();
if(brt!=ans){
cerr<<C<<": "<<brt<<" "<<ans<<endl;
assert(brt==ans);
}
#endif
}
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 1ms
memory: 3648kb
input:
1 23 1485 1 -12 1 -30 1 -20 1 6 1 24 1 5 1 31 1 14 1 -34 1 -22 1 -45 1 37 1 46 1 9 1 22 1 -9 1 9 1 -46 1 -47 1 39 1 36 1 -36 1 50
output:
491 481 474 476 484 486 496 501 489 482 467 479 495 498 505 502 505 490 474 487 499 487 504
result:
ok 23 numbers
Test #2:
score: -5
Wrong Answer
time: 0ms
memory: 3656kb
input:
12 1 13 79 59 21 32 13 85 40 74 15 49 56 3 31
output:
241
result:
wrong answer 1st numbers differ - expected: '189', found: '241'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #28:
score: 5
Accepted
time: 2ms
memory: 3744kb
input:
1999 2000 1 1 1 1 0 2 0 2 1 0 2 1 2 2 2 1 2 0 0 1 2 2 0 1 0 1 0 2 0 0 2 1 1 1 1 0 1 2 1 2 1 1 1 1 1 0 2 2 0 2 1 1 2 0 0 2 0 0 2 1 2 0 0 1 1 2 0 2 2 2 1 2 0 2 1 2 0 1 2 2 2 1 1 2 1 1 1 1 0 0 1 1 0 1 2 1 0 0 2 0 2 2 2 0 1 1 2 0 0 1 0 0 2 1 2 1 2 0 1 1 2 2 0 0 1 2 2 1 2 1 2 2 2 0 0 1 1 2 1 1 2 2 2 2 2 ...
output:
660 660 660 661 661 661 661 660 660 660 660 661 662 662 663 663 662 661 662 662 661 660 661 660 660 660 661 661 661 661 662 661 661 660 661 660 659 658 658 659 659 658 659 660 660 660 660 660 660 659 659 659 659 659 659 659 659 660 659 658 658 658 658 657 657 657 658 657 656 657 657 657 656 656 655 ...
result:
ok 2000 numbers
Test #29:
score: -5
Wrong Answer
time: 2ms
memory: 3740kb
input:
2000 2000 0 1 1 0 0 0 0 1 1 2 0 2 1 2 0 0 0 0 1 0 0 1 2 0 1 1 0 0 1 2 1 1 2 2 2 1 1 2 0 2 2 0 1 0 1 2 2 0 2 0 0 2 0 1 2 2 0 1 0 1 0 1 0 2 0 2 1 2 1 1 0 1 2 0 1 1 1 2 0 2 1 1 2 1 2 0 1 0 0 0 0 2 2 0 2 2 0 2 2 1 0 1 2 1 0 2 0 1 1 2 2 0 0 0 0 2 0 2 2 1 1 1 2 2 0 1 2 0 2 1 0 1 1 2 2 2 0 0 0 0 1 0 0 2 1 ...
output:
694 693 679 679 679 679 679 678 679 678 678 678 679 678 679 678 678 678 678 678 677 678 677 678 678 678 679 678 678 678 678 678 677 677 677 678 677 678 678 678 678 678 678 678 679 678 679 679 679 680 680 680 680 680 680 679 678 677 676 677 676 676 677 676 675 674 674 674 674 674 674 673 673 672 672 ...
result:
wrong answer 1st numbers differ - expected: '679', found: '694'
Subtask #4:
score: 0
Wrong Answer
Test #35:
score: 0
Wrong Answer
time: 2ms
memory: 3752kb
input:
2000 1999 0 1 0 3 0 1 0 0 0 0 0 0 0 2 0 0 0 0 3 1 1 0 2 0 0 3 0 0 0 0 0 4 0 0 1 0 1 0 0 0 0 1 2 1 0 0 0 0 7 0 1 3 1 0 1 1 0 3 2 1 0 1 1 3 3 1 0 2 0 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 2 3 0 1 0 3 3 0 0 0 0 1 0 1 2 0 0 2 2 0 1 2 1 2 0 0 0 1 1 0 1 2 0 0 0 0 2 0 5 0 0 0 0 0 1 0 0 2 0 1 2 0 1 0 0 0 2 0 ...
output:
670 670 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 666 665 665 665 665 665 665 665 665 665 665 665 665 665 665 665 665 665 666 666 666 666 666 666 666 666 666 666 666 666 666 665 ...
result:
wrong answer 1st numbers differ - expected: '666', found: '670'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%