답안 #1050310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050310 2024-08-09T08:39:23 Z vjudge1 Art Exhibition (JOI18_art) C++
100 / 100
216 ms 220580 KB
#include <bits/stdc++.h>
// #define DEBUG 1
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx,mmx,tune=native")
// #include <ext/pb_ds/detail/standard_policies.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
/* find_by_order() order_of_key() */
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif
#define elif else if
#define pb push_back
#define fast cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define str to_string
#define sz(x) int(x.size())
#define F first
#define S second
#define FOR(i, a, b) for (int i=a; i < (b); i++)
#define F0R(i, a) for (int i=0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b) - 1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--)
#define watch(x) cout << #x << " <----  " << x << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A, typename B>
inline bool umin(A& a, B b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
 
template<typename A, typename B>
inline bool umax(A& a, B b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<typename T>
T binpow(T b, T e, T m) {
    T r = 1;
    while(e > 0) {
        if(e & 1) r = r * b % m;
        b = b * b % m;
        e >>= 1;
    }
    return r;
}
using ll = long long;
using ld = long double;
using ull = unsigned long long;
inline ll rand(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}
const int N = 1e6 + 1;
const ll mod = 1e9 + 7;
const int INF = 1e9;
ll n, m, k, q;
int h1[4] = {1, 0, 0, -1};
int h2[4] = {0, -1, 1, 0};
ll a[N];
bool check(int x, int y) {
    return (x >= 0 && y >= 0 && x < n && y < m);
}
int go(char c) {
    return c - '0';
}
vector<ll> adj[N];
/* Problems solved, rank evolved. */

pair<ll, ll> sp[N][20];
ll b[N];
ll p[N];
pair<ll, ll> lt[N];
pair<ll, ll> qr(int l, int r){
  if(l > r) swap(l, r);
  int len = (r - l + 1);
  int st = 31 - __builtin_clz(len);
  return {min(sp[l][st].F, sp[r - (1 << st) + 1][st].F), max(sp[l][st].S, sp[r - (1 << st) + 1][st].S)};
}
int fbin(int x, int fr, int l, int r, int type){
  if(r < l){
    swap(r,l);
  }
  int lo = l;
  int hi = r;
  int ans = -1;
  while(lo <= hi){
    int mid = (lo + hi) / 2;
    if(qr(fr, mid).S != x){
      if(type == 1){
        lo = mid + 1;
      } else {
        hi = mid - 1;
      }
    } else {
      if(type == 1) {
        hi = mid - 1;
        ans = mid;
      } else {
        lo = mid + 1;
        ans = mid;
      }
    }
  }
  return ans;
}
void tourist() {
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    //     freopen("errors.txt", "w", stderr);
    // #endif
    cin >> n;
    for(int i = 1; i <= n; i++){
      cin >> a[i] >> b[i];
      lt[i] = {a[i], b[i]};
    }
    sort(lt + 1, lt + n + 1);
    p[0] = 0;
    for(int i = 1; i <= n; i++) {
      p[i] = p[i - 1] + lt[i].S;
      sp[i][0] = {-lt[i].F + p[i], -lt[i].F + p[i]};
    }
    
    for(int k = 1; k < 20; k++){
      for(int i = 1; i + (1 << k) - 1 <= n; i++){
        sp[i][k].F = min(sp[i][k - 1].F, sp[i + (1 << (k - 1))][k - 1].F);
        sp[i][k].S = max(sp[i][k - 1].S, sp[i + (1 << (k - 1))][k - 1].S);
      }
    }
    // cout min from one point
    ll ans = -INF;
    for(int i = 1; i <= n; i++){
        ans = max(ans, qr(i, n).S - p[i - 1] + lt[i].F);
    }
    cout << ans << '\n';
}

/*Give me some sunshine, give me some rain, its a beatifull day-ay-ay-ay...*/
int32_t main() {
    fast
    int tt = 1;
    // cin >> tt;
    while (tt--) {
        tourist();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 33368 KB Output is correct
2 Correct 4 ms 33112 KB Output is correct
3 Correct 4 ms 33116 KB Output is correct
4 Correct 4 ms 33224 KB Output is correct
5 Correct 4 ms 33116 KB Output is correct
6 Correct 4 ms 33300 KB Output is correct
7 Correct 4 ms 33116 KB Output is correct
8 Correct 4 ms 33116 KB Output is correct
9 Correct 4 ms 33116 KB Output is correct
10 Correct 4 ms 33112 KB Output is correct
11 Correct 4 ms 33112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 33368 KB Output is correct
2 Correct 4 ms 33112 KB Output is correct
3 Correct 4 ms 33116 KB Output is correct
4 Correct 4 ms 33224 KB Output is correct
5 Correct 4 ms 33116 KB Output is correct
6 Correct 4 ms 33300 KB Output is correct
7 Correct 4 ms 33116 KB Output is correct
8 Correct 4 ms 33116 KB Output is correct
9 Correct 4 ms 33116 KB Output is correct
10 Correct 4 ms 33112 KB Output is correct
11 Correct 4 ms 33112 KB Output is correct
12 Correct 4 ms 33112 KB Output is correct
13 Correct 4 ms 33112 KB Output is correct
14 Correct 4 ms 33112 KB Output is correct
15 Correct 4 ms 33116 KB Output is correct
16 Correct 4 ms 33300 KB Output is correct
17 Correct 4 ms 33116 KB Output is correct
18 Correct 4 ms 33112 KB Output is correct
19 Correct 4 ms 33116 KB Output is correct
20 Correct 4 ms 33116 KB Output is correct
21 Correct 4 ms 33116 KB Output is correct
22 Correct 4 ms 33116 KB Output is correct
23 Correct 4 ms 33116 KB Output is correct
24 Correct 4 ms 33116 KB Output is correct
25 Correct 4 ms 33240 KB Output is correct
26 Correct 4 ms 33116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 33368 KB Output is correct
2 Correct 4 ms 33112 KB Output is correct
3 Correct 4 ms 33116 KB Output is correct
4 Correct 4 ms 33224 KB Output is correct
5 Correct 4 ms 33116 KB Output is correct
6 Correct 4 ms 33300 KB Output is correct
7 Correct 4 ms 33116 KB Output is correct
8 Correct 4 ms 33116 KB Output is correct
9 Correct 4 ms 33116 KB Output is correct
10 Correct 4 ms 33112 KB Output is correct
11 Correct 4 ms 33112 KB Output is correct
12 Correct 4 ms 33112 KB Output is correct
13 Correct 4 ms 33112 KB Output is correct
14 Correct 4 ms 33112 KB Output is correct
15 Correct 4 ms 33116 KB Output is correct
16 Correct 4 ms 33300 KB Output is correct
17 Correct 4 ms 33116 KB Output is correct
18 Correct 4 ms 33112 KB Output is correct
19 Correct 4 ms 33116 KB Output is correct
20 Correct 4 ms 33116 KB Output is correct
21 Correct 4 ms 33116 KB Output is correct
22 Correct 4 ms 33116 KB Output is correct
23 Correct 4 ms 33116 KB Output is correct
24 Correct 4 ms 33116 KB Output is correct
25 Correct 4 ms 33240 KB Output is correct
26 Correct 4 ms 33116 KB Output is correct
27 Correct 5 ms 33368 KB Output is correct
28 Correct 5 ms 33372 KB Output is correct
29 Correct 5 ms 33372 KB Output is correct
30 Correct 5 ms 33328 KB Output is correct
31 Correct 5 ms 33372 KB Output is correct
32 Correct 5 ms 33232 KB Output is correct
33 Correct 5 ms 33348 KB Output is correct
34 Correct 5 ms 33372 KB Output is correct
35 Correct 5 ms 33372 KB Output is correct
36 Correct 5 ms 33372 KB Output is correct
37 Correct 5 ms 33372 KB Output is correct
38 Correct 5 ms 33372 KB Output is correct
39 Correct 5 ms 33372 KB Output is correct
40 Correct 5 ms 33372 KB Output is correct
41 Correct 5 ms 33380 KB Output is correct
42 Correct 5 ms 33372 KB Output is correct
43 Correct 5 ms 33372 KB Output is correct
44 Correct 5 ms 33236 KB Output is correct
45 Correct 5 ms 33372 KB Output is correct
46 Correct 5 ms 33372 KB Output is correct
47 Correct 5 ms 33372 KB Output is correct
48 Correct 5 ms 33368 KB Output is correct
49 Correct 4 ms 33372 KB Output is correct
50 Correct 5 ms 33372 KB Output is correct
51 Correct 5 ms 33372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 33368 KB Output is correct
2 Correct 4 ms 33112 KB Output is correct
3 Correct 4 ms 33116 KB Output is correct
4 Correct 4 ms 33224 KB Output is correct
5 Correct 4 ms 33116 KB Output is correct
6 Correct 4 ms 33300 KB Output is correct
7 Correct 4 ms 33116 KB Output is correct
8 Correct 4 ms 33116 KB Output is correct
9 Correct 4 ms 33116 KB Output is correct
10 Correct 4 ms 33112 KB Output is correct
11 Correct 4 ms 33112 KB Output is correct
12 Correct 4 ms 33112 KB Output is correct
13 Correct 4 ms 33112 KB Output is correct
14 Correct 4 ms 33112 KB Output is correct
15 Correct 4 ms 33116 KB Output is correct
16 Correct 4 ms 33300 KB Output is correct
17 Correct 4 ms 33116 KB Output is correct
18 Correct 4 ms 33112 KB Output is correct
19 Correct 4 ms 33116 KB Output is correct
20 Correct 4 ms 33116 KB Output is correct
21 Correct 4 ms 33116 KB Output is correct
22 Correct 4 ms 33116 KB Output is correct
23 Correct 4 ms 33116 KB Output is correct
24 Correct 4 ms 33116 KB Output is correct
25 Correct 4 ms 33240 KB Output is correct
26 Correct 4 ms 33116 KB Output is correct
27 Correct 5 ms 33368 KB Output is correct
28 Correct 5 ms 33372 KB Output is correct
29 Correct 5 ms 33372 KB Output is correct
30 Correct 5 ms 33328 KB Output is correct
31 Correct 5 ms 33372 KB Output is correct
32 Correct 5 ms 33232 KB Output is correct
33 Correct 5 ms 33348 KB Output is correct
34 Correct 5 ms 33372 KB Output is correct
35 Correct 5 ms 33372 KB Output is correct
36 Correct 5 ms 33372 KB Output is correct
37 Correct 5 ms 33372 KB Output is correct
38 Correct 5 ms 33372 KB Output is correct
39 Correct 5 ms 33372 KB Output is correct
40 Correct 5 ms 33372 KB Output is correct
41 Correct 5 ms 33380 KB Output is correct
42 Correct 5 ms 33372 KB Output is correct
43 Correct 5 ms 33372 KB Output is correct
44 Correct 5 ms 33236 KB Output is correct
45 Correct 5 ms 33372 KB Output is correct
46 Correct 5 ms 33372 KB Output is correct
47 Correct 5 ms 33372 KB Output is correct
48 Correct 5 ms 33368 KB Output is correct
49 Correct 4 ms 33372 KB Output is correct
50 Correct 5 ms 33372 KB Output is correct
51 Correct 5 ms 33372 KB Output is correct
52 Correct 173 ms 207700 KB Output is correct
53 Correct 172 ms 220244 KB Output is correct
54 Correct 172 ms 220332 KB Output is correct
55 Correct 181 ms 220580 KB Output is correct
56 Correct 176 ms 220200 KB Output is correct
57 Correct 173 ms 220324 KB Output is correct
58 Correct 184 ms 220268 KB Output is correct
59 Correct 178 ms 220244 KB Output is correct
60 Correct 169 ms 220208 KB Output is correct
61 Correct 200 ms 220240 KB Output is correct
62 Correct 173 ms 220332 KB Output is correct
63 Correct 181 ms 220332 KB Output is correct
64 Correct 216 ms 220240 KB Output is correct
65 Correct 170 ms 220240 KB Output is correct
66 Correct 176 ms 220244 KB Output is correct
67 Correct 197 ms 220352 KB Output is correct
68 Correct 196 ms 220244 KB Output is correct