답안 #1083906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083906 2024-09-04T13:46:18 Z May27_th Art Exhibition (JOI18_art) C++17
100 / 100
217 ms 56148 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define i64 long long
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
struct Tree{
  int n;
  vector<int64_t>lazy;
  vector<int64_t>st;
  Tree(int _n, int64_t _v): n(_n), st(_n * 4, _v), lazy(_n * 4, _v){};
  void push(int id){
    int64_t add = lazy[id];
    lazy[id * 2] += add, st[id * 2] += add;
    lazy[id * 2 + 1] += add, st[id * 2 + 1] += add;
    lazy[id] = 0;
  }
  void update(int id, int l, int r, int u, int v, int64_t val){
    if (v < l || u > r) return;
    if (u <= l && r <= v) {
      st[id] = val;
      // lazy[id] += val;
      return;
    }
    // push(id);
    int mid = (l + r)/2;
    update(id * 2, l, mid, u, v, val);
    update(id * 2 + 1, mid + 1, r, u, v, val);
    st[id] = max(st[id * 2], st[id * 2 + 1]);
  }
  i64 get(int id, int l, int r, int u, int v) {
    if (v < l || u > r) return -1000000000000000000;
    if (u <= l && r <= v) return st[id];
    int mid = (l + r)/2;
    return max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
  }
};
void Solve(void) {
  int N; cin >> N;
  Tree sum(N + 5, 0);
  vector<pair<i64, i64>> pictures(N);
  vector<i64> pref(N + 5, 0);
  for (int i = 0; i < N; i ++) {
    cin >> pictures[i].first >> pictures[i].second;
  }  
  sort(all(pictures));
  for (int i = 0; i < N; i ++) {
    pref[i + 1] = pref[i] + pictures[i].second;
    sum.update(1, 1, N, i + 1, i + 1, pref[i + 1] - pictures[i].first);
  }
  i64 ans = LLONG_MIN;
  for (int i = 1; i <= N; i ++) {
    ans = max(ans, sum.get(1, 1, N, i, N) - pref[i - 1] + pictures[i - 1].first);
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int Tests = 1; // cin >> Tests; 
  while (Tests --) {
    Solve();    
  }
}

Compilation message

art.cpp: In constructor 'Tree::Tree(int, int64_t)':
art.cpp:12:18: warning: 'Tree::st' will be initialized after [-Wreorder]
   12 |   vector<int64_t>st;
      |                  ^~
art.cpp:11:18: warning:   'std::vector<long int> Tree::lazy' [-Wreorder]
   11 |   vector<int64_t>lazy;
      |                  ^~~~
art.cpp:13:3: warning:   when initialized here [-Wreorder]
   13 |   Tree(int _n, int64_t _v): n(_n), st(_n * 4, _v), lazy(_n * 4, _v){};
      |   ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 856 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 856 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 2 ms 860 KB Output is correct
35 Correct 2 ms 980 KB Output is correct
36 Correct 2 ms 860 KB Output is correct
37 Correct 2 ms 860 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 2 ms 860 KB Output is correct
40 Correct 2 ms 860 KB Output is correct
41 Correct 2 ms 860 KB Output is correct
42 Correct 2 ms 1016 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 2 ms 1016 KB Output is correct
45 Correct 2 ms 1032 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Correct 2 ms 1016 KB Output is correct
48 Correct 2 ms 856 KB Output is correct
49 Correct 2 ms 856 KB Output is correct
50 Correct 2 ms 856 KB Output is correct
51 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 856 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 856 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 2 ms 860 KB Output is correct
35 Correct 2 ms 980 KB Output is correct
36 Correct 2 ms 860 KB Output is correct
37 Correct 2 ms 860 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 2 ms 860 KB Output is correct
40 Correct 2 ms 860 KB Output is correct
41 Correct 2 ms 860 KB Output is correct
42 Correct 2 ms 1016 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 2 ms 1016 KB Output is correct
45 Correct 2 ms 1032 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Correct 2 ms 1016 KB Output is correct
48 Correct 2 ms 856 KB Output is correct
49 Correct 2 ms 856 KB Output is correct
50 Correct 2 ms 856 KB Output is correct
51 Correct 2 ms 860 KB Output is correct
52 Correct 207 ms 55888 KB Output is correct
53 Correct 209 ms 56036 KB Output is correct
54 Correct 213 ms 56148 KB Output is correct
55 Correct 205 ms 56036 KB Output is correct
56 Correct 204 ms 56148 KB Output is correct
57 Correct 208 ms 56120 KB Output is correct
58 Correct 205 ms 56016 KB Output is correct
59 Correct 212 ms 56036 KB Output is correct
60 Correct 211 ms 56148 KB Output is correct
61 Correct 209 ms 55892 KB Output is correct
62 Correct 208 ms 56144 KB Output is correct
63 Correct 201 ms 56144 KB Output is correct
64 Correct 203 ms 56144 KB Output is correct
65 Correct 213 ms 56148 KB Output is correct
66 Correct 217 ms 56144 KB Output is correct
67 Correct 213 ms 56144 KB Output is correct
68 Correct 208 ms 56020 KB Output is correct