QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#615920 | #9440. Train Seats | ucup-team3564# | WA | 0ms | 13884kb | C++20 | 3.4kb | 2024-10-05 20:57:03 | 2024-10-05 20:57:34 |
Judging History
answer
// MagicDark
#include <bits/stdc++.h>
#define int long long
#define mid ((l + r) >> 1)
#define ls num << 1
#define rs ls | 1
#define li ls, l, mid
#define ri rs, mid + 1, r
#define debug cerr << "\033[32m[" << __LINE__ << "]\033[0m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T& x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T& x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x *= f;
}
const int N = 2e5 + 10;
int n, a[N], m, sta[N], rk[N * 2];
ll sum;
// ll t1[N], t2[N];
vector <int> ins[N], del[N];
struct Node {
int cnt;
ll sum, val;
} info[N << 3], t1[N], t2[N];
pair <Node, int> tt[N << 1];
bool operator < (Node x, Node y) {
return y.cnt * x.sum < x.cnt * y.sum;
}
bool operator > (Node x, Node y) {
return y.cnt * x.sum > x.cnt * y.sum;
}
Node operator + (Node x, Node y) {
x.val += y.val + x.sum * y.cnt;
x.sum += y.sum;
x.cnt += y.cnt;
return x;
}
Node& operator += (Node& x, Node y) {
return x = x + y;
}
void pushup(int num) {
info[num] = info[ls] + info[rs];
}
void modify(int num, int l, int r, int x, Node y) {
if (l == r) {
info[num] = y;
return;
}
if (mid >= x) modify(li, x, y);
else modify(ri, x, y);
pushup(num);
}
ll mx;
signed main() {
read(n), read(m);
// ll w = 0;
F(i, 1, n) read(a[i]);
a[n + 1] = m + 1;
DF(i, n + 1, 1) a[i] -= a[i - 1];
n++;
// F(i, 1, n) a[i] *= - 1;
F(i, 1, n) sum += a[i];//, w += sum;//, b[i] = a[i];
// sort(b + 1, b + n + 1);
// int m = unique(b + 1, b + n + 1) - b - 1;
// F(i, 1, n) a[i] = lower_bound(b + 1, b + m + 1, a[i]) - b;
int cnt = 0;
F(i, 1, n) {
t1[i] = {1, a[i], a[i]};
while (cnt && t1[i] > t1[sta[cnt]]) {
del[i].push_back(sta[cnt]);
t1[i] += t1[sta[cnt--]];
}
tt[i] = make_pair(t1[i], i);
sta[++cnt] = i;
}
cnt = 0;
DF(i, n, 1) {
t2[i] = {1, a[i], a[i]};
while (cnt && t2[i] > t2[sta[cnt]]) {
ins[i + 1].push_back(sta[cnt]);
t2[i] += t2[sta[cnt--]];
}
tt[i + n] = make_pair(t2[i], n + i);
sta[++cnt] = i;
}
sort(tt + 1, tt + 2 * n + 1);
F(i, 1, 2 * n) rk[tt[i].second] = i;
// Node w = {0, 0, 0};
while (cnt) {
// w += t2[sta[cnt]];
modify(1, 1, n * 2, rk[n + sta[cnt]], t2[sta[cnt]]);
// debug << t2[sta[cnt]].sum << " " << t2[sta[cnt]].val << endl;
cnt--;
// ins[1].push_back(sta[cnt--]);
// debug << w.cnt << " " << w.sum << " " << w.val << endl;
}
// debug << info[1].sum << " " << info[1].val << endl;
// debug << w << endl;
F(i, 1, n) {
for (int j: ins[i + 1]) modify(1, 1, n * 2, rk[n + j], t2[j]);//, debug << "+ " << j << endl;
for (int j: del[i - 1]) modify(1, 1, n * 2, rk[j], (Node) {0, 0, 0});//, debug << "- " << j << endl;
// debug << "- " << i << endl;
modify(1, 1, n * 2, rk[n + i], (Node) {0, 0, 0});
// debug << "! " << info[1].sum << " " << info[1].val << endl;
chkmax(mx, (info[1].val + (ll) a[i] * (n - 1)));
modify(1, 1, n * 2, rk[i], t1[i]);
}
cout << mx;
return 0;
}
/* why?
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 11848kb
input:
3 10 3 7 10
output:
28
result:
ok "28"
Test #2:
score: 0
Accepted
time: 0ms
memory: 13884kb
input:
5 20 3 10 11 14 17
output:
73
result:
ok "73"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 13868kb
input:
10 1000000000 136909656 243332691 643531997 505919307 43553384 657638276 57213246 179732866 357373203 182482400
output:
7174795384
result:
wrong answer 1st words differ - expected: '7649951260', found: '7174795384'