QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#300218 | #7582. Snowy Smile | I_Love_Sonechka# | WA | 2402ms | 3704kb | C++14 | 3.1kb | 2024-01-07 21:21:39 | 2024-01-07 21:21:39 |
Judging History
answer
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#define local_shit freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout);
#else
#define local_shit
#endif
// io macros
#define fastio ios::sync_with_stdio(false); cin.tie(nullptr);
#define make_test_shit freopen("inp.txt", "w", stdout);
// c++ short types
#define Int long long
#define vt vector
#define pi pair<int, int>
// code macros
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ins insert
#define mp make_pair
// loops macros
#define each(x, a) for(auto &x: a)
// some functions
template<typename T>
void umax(T &a, const T &b) { a = max(a,b); }
template<typename T>
void umin(T &a, const T &b) { a = min(a,b); }
void whattime() { cout << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; }
template<typename T>
T firsttrue(T l, T r, function<bool(T)> f) {
while(r - l > 1) {
T m = (l+r)/2;
if(f(m)) {
r = m;
} else {
l = m;
}
}
return r;
}
template<typename T>
T lasttrue(T l, T r, function<bool(T)> f) {
while(r - l > 1) {
T m = (l+r)/2;
if(f(m)) {
l = m;
} else {
r = m;
}
}
return l;
}
class segtree {
struct node {
Int pref_max, suf_max, sum, max_sum;
node(Int v = 0) {
sum = v;
pref_max = suf_max = max_sum = max(0ll, v);
}
friend node merge(node &a, node &b) {
node c(a.sum+b.sum);
c.pref_max = max(a.pref_max, a.sum + b.pref_max);
c.suf_max = max(b.suf_max, b.sum + a.suf_max);
c.max_sum = max({a.max_sum, b.max_sum, a.suf_max + b.pref_max});
return c;
}
};
public:
vt<node> t;
int n;
segtree(int _n) : n(_n) {
t.assign(2*n, {0});
}
void update(int p, int dx) {
t[p+n] = {t[p+n].sum + dx};
for(p+=n; p > 1; p >>= 1) {
node l = t[p], r = t[p^1];
if(p & 1) {
swap(l, r);
}
t[p>>1] = merge(l, r);
}
}
Int get(int l, int r) {
node left = {0}, right = {0};
for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
if(l & 1) {
left = merge(left, t[l++]);
}
if(r & 1) {
right = merge(t[--r], right);
}
}
return merge(left, right).max_sum;
}
};
void solver() {
int n; cin >> n;
vt<array<int, 3>> points(n);
for(auto &p: points) {
for(auto &x: p) {
cin >> x;
}
}
for(int j = 0; j < 2; ++j) {
map<int, int> ids;
for(auto p: points) {
ids[p[j]];
}
int id = 0;
for(auto &x: ids) {
x.second = id++;
}
for(auto &p: points) {
p[j] = ids[p[j]];
}
}
long long res = 0;
for(int w = 1; w <= n; ++w) {
vt<vt<array<int, 2>>> addends(n);
for(auto p: points) {
addends[p[0]].push_back({p[1], p[2]});
if(p[0] + w < n) {
addends[p[0]+w].push_back({p[1], -p[2]});
}
}
segtree st(n);
for(int i = 0; i < n; ++i) {
for(auto a : addends[i]) {
st.update(a[0], a[1]);
}
res = max(res, st.get(0, n-1));
}
}
cout << res << '\n';
}
int main()
{
fastio;
int tt = 1;
cin >> tt;
for(int t = 0; t < tt; ++t) {
solver();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3548kb
input:
2 4 1 1 50 2 1 50 1 2 50 2 2 -500 2 -1 1 5 -1 1 1
output:
100 6
result:
ok 2 number(s): "100 6"
Test #2:
score: -100
Wrong Answer
time: 2402ms
memory: 3704kb
input:
52 10 30 -1 -40065867 -15 -74 -695603735 -14 3 -847010045 33 -92 -458180374 -88 -86 -488393753 50 -91 -949931576 39 -99 -168684248 -29 64 783067879 14 -5 -104144786 -67 90 492127865 10 -29 -70 151800541 54 41 -677722362 -85 -72 766300892 -47 -90 -74384884 -12 -56 679506148 0 -41 -30038154 -4 -6 -254...
output:
783067879 2084179225 1734353870 1018976777 2580295428 1309403622 2358891488 2143566532 1602649268 2112317422 848977210 2051225311 1504141589 1571719735 1313345276 2039708041 1526772930 1368470878 866267413 1162858653 1878414495 1706604892 1822460963 1942258759 2608382535 2090539403 666502909 1466069...
result:
wrong answer 1st numbers differ - expected: '1275195744', found: '783067879'