답안 #536295

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
536295 2022-03-12T18:14:59 Z cadmiumsky 3단 점프 (JOI19_jumps) C++14
100 / 100
1564 ms 68012 KB
#include <bits/stdc++.h>
using namespace std;

const int nmax = 5e5 + 5;
const int nextpow = 1 << 20;
const int inf = 1e9;

int n;
vector<int> v;

namespace AINT {
  struct Node {
    int vab, x, sum;
    Node operator +(const Node& a) const {
      return Node{-inf, max(x, a.x), max(sum, a.sum)};
    }
    void tag(const int& a)  {
      if(vab < a)
        vab = a, sum = max(sum, a + x);
    } 
  } aint[nmax * 4], iden = Node{-inf, -inf, -inf};
  int lazy[nmax * 4];
  void apply(int node, int cl, int cr) {
    if(lazy[node] == -1)
      return;
    aint[node].tag(lazy[node]);
    if(cl != cr) {
      lazy[2 * node] = max(lazy[node], lazy[2 * node]);
      lazy[2 * node + 1] = max(lazy[node], lazy[2 * node + 1]);
    }
    //aint[node] = aint[node] + aint[2 * node] + aint[2 * node + 1];
    lazy[node] = -1;
  }
  void prop(int node, int cl, int cr) {
    apply(node, cl, cr);
    if(cl == cr)
      return;
    int mid = cl + cr >> 1;
    apply(2 * node, cl, mid);
    apply(2 * node + 1, mid + 1, cr);
  }
  void upd(int l, int r, int val, int node = 1, int cl = 0, int cr = n) {
    prop(node, cl, cr);
    if(cr < l || r < cl)
      return;
    if(l <= cl && cr <= r) {
      //cout << "cine " << l << ' ' << cl << ' ' << cr << ' ' << r << "  +" << val << '\n';
      lazy[node] = val;
      prop(node, cl, cr);
      return;
    }
    int mid = cl + cr >> 1;
    upd(l, r, val, 2 * node, cl, mid);
    upd(l, r, val, 2 * node + 1, mid + 1, cr);
    int sus = aint[node].vab;
    aint[node] = aint[2 * node] + aint[2 * node + 1];
    aint[node].vab = sus;
  }
  Node query(int l, int r, int node = 1, int cl = 0, int cr = n) {
    prop(node, cl, cr);
    if(cr < l || r < cl)
      return iden;
    if(l <= cl && cr <= r) {
      //cout << "cum " << l << ' ' << cl << ' ' << cr << ' ' << r << ' ' << aint[node].x << ' ' << aint[node].vab << ' ' << aint[node].sum << '\n';
      return aint[node];
    }
    int mid = cl + cr >> 1;
    Node rez = query(l, r, 2 * node, cl, mid) + query(l, r, 2 * node + 1, mid + 1, cr);
    return rez;
  }
  int qry(int l, int r) {
    return query(l, r).sum;
  }
  void construct(int node = 1, int cl = 0, int cr = n) {
    aint[node] = iden;
    lazy[node] = -1;
    if(cl == cr) {
      aint[node].x = v[cl];
      return;
    }
    int mid = cl + cr >> 1;
    construct(2 * node, cl, mid);
    construct(2 * node + 1, mid + 1, cr);
    aint[node] = aint[2 * node] + aint[2 * node + 1];
    return;
  }

};

vector<tuple<int,int,int> > rez;
vector<int> qs[nmax];

static void candid(int l, int r) {
  int sim = r + (r - l);
  if(sim >= n)
    return;
  //cerr << l << ' ' << r << ' ' <<sim << ' ' << n << '\n';
  AINT::upd(sim, n, v[l] + v[r]);
  return;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> n;
  v.resize(n);
  #define stack deobiceicineintreaba
  vector<int> stack;
  for(auto &x : v) cin >> x;
  stack.push_back(n);
  v.push_back(-1e9 -5);
  AINT::construct();
  v.back() *= -1;
  //cerr << v.size() << '\n',
  cin >> q;
  rez.resize(q);
  int i = 0;
  for(auto &[a, b, c] : rez)
    cin >> a >> b, --a, --b, c = 0, qs[a].push_back(i++);
  int l, r, val;
  for(int i = n - 1; i >= 0; i--) {
    while(v[stack.back()] <= v[i]) {
      candid(i, stack.back());
      stack.pop_back();
    }
    candid(i, stack.back());
     
    stack.push_back(i);
    for(auto x : qs[i]) {
      tie(l, r, val) = rez[x];
      val = AINT::qry(l, r);
      //cout << val << '\n';
      rez[x] = {l, r, val};
    }
  }
  for(auto [a, b, c] : rez)
    cout << c << '\n';
}
#warning cine cu scopul de a fucking intreba

Compilation message

jumps.cpp:140:2: warning: #warning cine cu scopul de a fucking intreba [-Wcpp]
  140 | #warning cine cu scopul de a fucking intreba
      |  ^~~~~~~
jumps.cpp: In function 'void AINT::prop(int, int, int)':
jumps.cpp:38:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
jumps.cpp: In function 'void AINT::upd(int, int, int, int, int, int)':
jumps.cpp:52:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
jumps.cpp: In function 'AINT::Node AINT::query(int, int, int, int, int)':
jumps.cpp:67:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   67 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
jumps.cpp: In function 'void AINT::construct(int, int, int)':
jumps.cpp:81:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   81 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
jumps.cpp: In function 'int main()':
jumps.cpp:119:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  119 |   for(auto &[a, b, c] : rez)
      |             ^
jumps.cpp:137:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  137 |   for(auto [a, b, c] : rez)
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 6 ms 11988 KB Output is correct
5 Correct 6 ms 12020 KB Output is correct
6 Correct 7 ms 12048 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 7 ms 11988 KB Output is correct
9 Correct 6 ms 11988 KB Output is correct
10 Correct 7 ms 11988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 6 ms 11988 KB Output is correct
5 Correct 6 ms 12020 KB Output is correct
6 Correct 7 ms 12048 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 7 ms 11988 KB Output is correct
9 Correct 6 ms 11988 KB Output is correct
10 Correct 7 ms 11988 KB Output is correct
11 Correct 456 ms 26956 KB Output is correct
12 Correct 445 ms 26704 KB Output is correct
13 Correct 440 ms 26656 KB Output is correct
14 Correct 450 ms 26748 KB Output is correct
15 Correct 447 ms 26756 KB Output is correct
16 Correct 444 ms 26096 KB Output is correct
17 Correct 441 ms 26116 KB Output is correct
18 Correct 448 ms 25972 KB Output is correct
19 Correct 445 ms 26700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 237 ms 21052 KB Output is correct
2 Correct 115 ms 22852 KB Output is correct
3 Correct 127 ms 21036 KB Output is correct
4 Correct 235 ms 21040 KB Output is correct
5 Correct 228 ms 21040 KB Output is correct
6 Correct 240 ms 21052 KB Output is correct
7 Correct 236 ms 21064 KB Output is correct
8 Correct 230 ms 21036 KB Output is correct
9 Correct 236 ms 21060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 6 ms 11988 KB Output is correct
5 Correct 6 ms 12020 KB Output is correct
6 Correct 7 ms 12048 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 7 ms 11988 KB Output is correct
9 Correct 6 ms 11988 KB Output is correct
10 Correct 7 ms 11988 KB Output is correct
11 Correct 456 ms 26956 KB Output is correct
12 Correct 445 ms 26704 KB Output is correct
13 Correct 440 ms 26656 KB Output is correct
14 Correct 450 ms 26748 KB Output is correct
15 Correct 447 ms 26756 KB Output is correct
16 Correct 444 ms 26096 KB Output is correct
17 Correct 441 ms 26116 KB Output is correct
18 Correct 448 ms 25972 KB Output is correct
19 Correct 445 ms 26700 KB Output is correct
20 Correct 237 ms 21052 KB Output is correct
21 Correct 115 ms 22852 KB Output is correct
22 Correct 127 ms 21036 KB Output is correct
23 Correct 235 ms 21040 KB Output is correct
24 Correct 228 ms 21040 KB Output is correct
25 Correct 240 ms 21052 KB Output is correct
26 Correct 236 ms 21064 KB Output is correct
27 Correct 230 ms 21036 KB Output is correct
28 Correct 236 ms 21060 KB Output is correct
29 Correct 1562 ms 50356 KB Output is correct
30 Correct 1272 ms 65356 KB Output is correct
31 Correct 1274 ms 61252 KB Output is correct
32 Correct 1544 ms 61196 KB Output is correct
33 Correct 1541 ms 61280 KB Output is correct
34 Correct 1560 ms 59004 KB Output is correct
35 Correct 1564 ms 58780 KB Output is correct
36 Correct 1553 ms 58756 KB Output is correct
37 Correct 1560 ms 60108 KB Output is correct
38 Correct 1149 ms 67896 KB Output is correct
39 Correct 1181 ms 68012 KB Output is correct
40 Correct 1149 ms 64672 KB Output is correct
41 Correct 1161 ms 64084 KB Output is correct
42 Correct 1172 ms 64080 KB Output is correct
43 Correct 1212 ms 65816 KB Output is correct
44 Correct 1243 ms 67240 KB Output is correct
45 Correct 1274 ms 67276 KB Output is correct
46 Correct 1224 ms 64164 KB Output is correct
47 Correct 1245 ms 63696 KB Output is correct
48 Correct 1222 ms 63688 KB Output is correct
49 Correct 1240 ms 65812 KB Output is correct
50 Correct 1332 ms 65024 KB Output is correct
51 Correct 1339 ms 65100 KB Output is correct
52 Correct 1318 ms 62580 KB Output is correct
53 Correct 1326 ms 62156 KB Output is correct
54 Correct 1305 ms 62220 KB Output is correct
55 Correct 1370 ms 63940 KB Output is correct