This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define inf 1e18
#define fi first
#define se second
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define endl '\n'
#define pi 3.14159265359
#define TASKNAME "hack"
using namespace std;
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
const int MAXN = 2e6 + 9;
/**
1 vong tron tim cach choi sao cho duoc nhieu diem nhat.
1 tactic khi choi la dp. Nhung ma, lieu co cach nao ngoai dp ko.
Tập đỉnh mà mình hack được và tập đỉnh mà họ hack được sẽ phải là n / 2.
Với mỗi thằng mình sẽ muồn tìm cái sliding windown nhỏ nhất mà chứa nó thì kết quả sẽ là cái sliding đấy.
**/
int a[MAXN], pre[MAXN], answer[MAXN];
int n;
int getRange(int l, int r){
return pre[r] - pre[l - 1];
}
struct segmentTree{
struct Node{
int mn = inf;
};
vector<Node> st;
segmentTree(int sz = 0){
st.resize(sz * 4 + 9);
}
void getPos(int nn, int l, int r, int pos, int &ans){
minimize(ans, st[nn].mn);
if (l == r){
return;
}
int mid = (l + r) >> 1;
if (pos <= mid) getPos(nn << 1, l, mid, pos, ans);
else getPos(nn << 1 | 1, mid + 1, r, pos, ans);
}
void changeMin(int nn, int l, int r, int u, int v, int x){
if (l >= u and r <= v) {
minimize(st[nn].mn, x);
return;
}
if (l > v or r < u) return;
int mid = (l + r) >> 1;
changeMin(nn << 1, l, mid, u, v, x);
changeMin(nn << 1 | 1, mid + 1, r, u, v, x);
}
};
main()
{
fast;
if (fopen(TASKNAME".inp","r")){
freopen(TASKNAME".inp","r",stdin);
freopen(TASKNAME".out","w",stdout);
}
cin>>n;
segmentTree opt(n + 1);
FOR(i, 1, n){
cin >> a[i];
a[i + n] = a[i];
a[i + 2 * n] = a[i];
}
FOR(i, 1, 3 * n){
pre[i] = pre[i - 1] + a[i];
}
memset(answer, 0x3f,sizeof(answer));
int ans = 0;
int taken = n / 2 + (n&1);
int sum = 0;
FOR(i, taken, 3 * n){
int sum = pre[i] - pre[i - taken];
int l = (i - taken + 1) % n + 1;
int r = i % n + 1;
if (l > r) {
opt.changeMin(1, 1, n, l, n, sum);
opt.changeMin(1, 1, n, 1, r, sum);
}
else{
opt.changeMin(1, 1, n, l, r, sum);
}
// FOR(j, i - taken + 1, i){
//
// minimize(answer[j % n + 1], sum);
// }
}
FOR(i, 1, n){
int res = inf;
opt.getPos(1, 1, n, i, res);
maximize(ans, res);
}
cout << ans << endl;
}
/**
Warning:
Đọc sai đề???
Cận lmao
Code imple thiếu case nào không.
Limit.
**/
Compilation message (stderr)
hac.cpp:74:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
74 | main()
| ^~~~
hac.cpp: In function 'int main()':
hac.cpp:96:9: warning: unused variable 'sum' [-Wunused-variable]
96 | int sum = 0;
| ^~~
hac.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
78 | freopen(TASKNAME".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
hac.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
79 | freopen(TASKNAME".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |