QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#556233 | #2299. Heating Up | qwqqwqqwqe | WA | 2899ms | 303916kb | C++17 | 2.9kb | 2024-09-10 16:06:58 | 2024-09-10 16:06:58 |
Judging History
answer
#include"bits/stdc++.h"
#define _det(...) fprintf(stderr,__VA_ARGS__)
#define Print(a) cerr<<a<<"\n"
#define IOS ios::sync_with_stdio(0);cin.tie(0)
#define Cases int T;cin>>T;while(T--)
#define Debug(in) cerr<<#in<<" = "<<(in)<<"\n"
#define Watch(in) Detect;Debug(in);
#define Detect _det("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define ll long long
using namespace std;
const int maxn = 1e6+5;
ll a[maxn];
ll p[maxn];
vector<int> E[maxn];
int n;
int vis[maxn];
int L[maxn]; int R[maxn];
int sz[maxn];
void DFS (int u) {
for (int v: E[u]) {
if (vis[v]) {
continue;
}
vis[v] = true;
DFS(v);
sz[u] += sz[v];
}
}
int read () {
int x = 0;
char c = getchar();
while(c<'0' || c>'9'){
c = getchar();
}
while(c>='0' && c<='9'){
x = x*10+c-'0';
c = getchar();
}
return x;
}
int check (ll mid) {
//Debug(mid);
for (int i=1;i<=n+n;i++) {
E[i].clear();
sz[i] = 1;
}
for (int i=1;i<=n+n;i++) {
int to = lower_bound(p+i,p+n+n+1,a[i]+p[i]-mid)-p;
if (to > i) R[i] = to;
else R[i] = i;
}
for (int i=1;i<=n+n;i++) {
int to = upper_bound(p,p+i+1,p[i-1]+mid-a[i])-p;
if (to < i) L[i] = to;
else L[i] = i;
}
pair<ll,ll> Rm = {-5e18,5e18};
for (int i=n+n;i>=1;i--) {
if (R[i] < Rm.second) {
Rm = {R[i],i};
}
if (Rm.first > R[i]) {
R[i] = Rm.first;
}
if (Rm.first <= R[i]) {
Rm = {R[i],i};
}
//Debug(R[i]);
}
pair<ll,ll> Lm = {5e18,-5e18}; //mx, from
for (int i=1;i<=n+n;i++) {
if (L[i] > Lm.second) {
Lm = {L[i],i};
}
if (Lm.first < L[i]) {
L[i] = Lm.first;
}
if (Lm.first >= L[i]) {
Lm = {L[i],i};
}
//Debug(L[i]);
}
for (int i=1;i<=n+n;i++) {
if (i == L[i]) L[i] = i-1;
if (i == R[i]) R[i] = i+1;
E[L[i]].push_back(i);
E[R[i]].push_back(i);
}
for (int i=1;i<=n+n;i++) {
vis[i] = false;
}
for (int i=1;i<=n+n;i++) {
if (a[i] <= mid) {
vis[i] = true;
DFS(i);
}
}
for (int i=1;i<=n+n;i++) {
//Debug(sz[i]);
if (sz[i] >= n) {
return true;
}
}
return false;
}
int main () {
n = read();
for (int i=1;i<=n;i++) {
a[i] = read();
a[i+n] = a[i];
}
for (int i=1;i<=n+n;i++) {
p[i] = p[i-1]+a[i];
}
p[n+n+1] = 5e18;
ll left = 0;
ll right = 1e13;
ll ans = -1;
while (left<=right) {
ll mid = (left+right)/2;
if (check(mid)) {
right = mid-1;
ans = mid;
}
else left = mid+1;
}
printf("%lld", ans);
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 38552kb
input:
4 10 20 15 1
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 2451ms
memory: 303916kb
input:
500000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 2461ms
memory: 302312kb
input:
500000 500000 499999 499998 499997 499996 499995 499994 499993 499992 499991 499990 499989 499988 499987 499986 499985 499984 499983 499982 499981 499980 499979 499978 499977 499976 499975 499974 499973 499972 499971 499970 499969 499968 499967 499966 499965 499964 499963 499962 499961 499960 499959...
output:
1
result:
ok single line: '1'
Test #4:
score: -100
Wrong Answer
time: 2899ms
memory: 200576kb
input:
500000 269655 357411 31288 467020 110496 411556 112354 389593 171879 31947 4478 451939 305813 353339 49648 499863 157385 370552 9830 451015 205703 127891 152977 102706 178312 99678 251482 407026 65794 348294 45973 39969 169990 115902 287834 225236 292268 427507 131002 392853 312830 353489 390159 370...
output:
2871
result:
wrong answer 1st lines differ - expected: '13561', found: '2871'