Submission #171401

# Submission time Handle Problem Language Result Execution time Memory
171401 2019-12-28T15:35:10 Z ne4eHbKa Divide and conquer (IZhO14_divide) C++17
0 / 100
5 ms 1272 KB
//{ <defines>
#ifndef _LOCAL
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
#endif

#include <bits/stdc++.h>
using namespace std;

#define fr(i, n) for(int i = 0; i < n; ++i)
#define fo(n) fr(i, n)

#define re return
#define ef else if
#define ifn(x) if(!(x))
#define _  << ' ' <<

#define ft first
#define sd second
#define ve vector
#define pb push_back
#define eb emplace_back

#define sz(x) int(x.size())
#define pw(x) (1 << (x))
#define PW(x) (1ll << (x))
#define bnd(x) x.begin(), x.end()
#define clr(x, y) memset(x, y, sizeof x)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef ve<int> vi;

const int oo = 2e9;
const ll OO = 4e18;
//const ld pi = arg(complex<ld>(-1, 0));
//const ld pi2 = pi + pi;
const int md = 0x3b800001;
const int MD = 1e9 + 7;

inline ll time() {re chrono :: system_clock().now().time_since_epoch().count();}
mt19937 rnd(time());
mt19937_64 RND(time());

template<typename t> inline void umin(t &a, t b) {a = min(a, b);}
template<typename t> inline void umax(t &a, t b) {a = max(a, b);}
//} </defines>
const int N = 2e5 + 228;

ll d[N], g[N], e[N], c[N];
int n, x[N], fe[N];

void upd(int &a, int b) {a < 0 ? a = b : b < 0 ? a = a : a > b ? a = b : 0;}
void fupd(int i, int v) {for(i++; i < N; i += i & -i) upd(fe[i], v);}
int fget(int i) {int v = -1; for(i++; i; i -= i & -i) upd(v, fe[i]); re v;}

#define f for(int i = 1; i <= n; ++i)
void solve() {
    clr(fe, -1);
    cin >> n;
    f cin >> x[i] >> g[i] >> d[i];
    partial_sum(g + 1, g + n + 1, g + 1);
    partial_sum(d + 1, d + n + 1, d + 1);
    f c[i] = d[i] - x[i];
    f e[i] = d[i - 1] - x[i];
    ll *p[n + n];
    fo(n) p[i] = &c[i + 1];
    fo(n) p[n + i] = &e[i + 1];
    sort(p, p + n + n, [] (ll *a, ll *b) {re *a < *b;});
    int u[n + n];
    fo(n + n) u[i] = i ? u[i - 1] + (*p[i - 1] != *p[i]) : 1;
    fo(n + n) *p[i] = u[i];
    ll ans = 0;
    f {
        fupd(e[i], i);
        int h = fget(c[i]);
        if(~h) umax(ans, g[i] - g[h - 1]);
    }
    cout << ans << endl;
}

int main() {
#ifdef _LOCAL
    freopen("in.txt", "r", stdin);
    int tests; cin >> tests;
    fo(tests) {
		cerr << "case #" << i+1 << endl;
		solve();
	}
#else
    freopen("divide.in", "r", stdin);
    freopen("divide.out", "w", stdout);
    ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	solve();
#endif
	return 0;
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:94:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("divide.in", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:95:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("divide.out", "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1148 KB Output isn't correct
2 Halted 0 ms 0 KB -