답안 #1016957

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016957 2024-07-08T16:19:23 Z MilosMilutinovic Progression (NOI20_progression) C++14
48 / 100
3000 ms 308820 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX = 300300;
const long long inf = (long long) 1e18;

struct Value { 
  struct Node {
    long long sum;
    long long coeff;
    Node(long long _sum = 0, long long _coeff = 0) : sum(_sum), coeff(_coeff) {}
  };

  int n;
  Node st[8 * MAX];

  void Modify(int id, int l, int r, int ll, int rr, long long x, long long y) {
    if (ll <= l && r <= rr) {
      st[id].sum += x;
      st[id].coeff += y;
      return;
    }
    int mid = (l + r) >> 1;
    if (rr <= mid) {
      Modify(id * 2, l, mid, ll, rr, x, y);
    } else if (ll > mid) {
      Modify(id * 2 + 1, mid + 1, r, ll, rr, x, y);
    } else {
      Modify(id * 2, l, mid, ll, rr, x, y);
      Modify(id * 2 + 1, mid + 1, r, ll, rr, x, y);
    }
  }

  Node Query(int id, int l, int r, int p) {
    if (l == r) {
      return st[id];
    }
    int mid = (l + r) >> 1;
    Node nd;
    if (p <= mid) {
      nd = Query(id * 2, l, mid, p);
    } else {
      nd = Query(id * 2 + 1, mid + 1, r, p);
    }
    return {st[id].sum + nd.sum, st[id].coeff + nd.coeff};
  }

  long long Get(int i) {
    Node nd = Query(1, 0, n - 1, i); 
    return nd.sum + nd.coeff * i;
  }
} val;

struct Solver {
  struct Node {
    int len;
    int mx;
    int mx_l;
    int mx_r;
    long long val_l;
    long long val_r;
    long long lzy_add;
    long long lzy_set;
    Node() {
      lzy_set = inf;
      lzy_add = 0;
    }
  };

  Node Merge(Node a, Node b) {
    Node nd;
    nd.len = a.len + b.len;
    nd.mx = max(a.mx, b.mx);
    nd.mx_l = a.mx_l;
    nd.mx_r = b.mx_r;
    if (a.val_r == b.val_l) {
      nd.mx = max(nd.mx, a.mx_r + b.mx_l);
      if (a.mx_l == a.len) {
        nd.mx_l = max(nd.mx_l, a.len + b.mx_l);
      }
      if (b.mx_r == b.len) {
        nd.mx_r = max(nd.mx_r, a.mx_r + b.len);
      }
    }
    nd.val_l = a.val_l;
    nd.val_r = b.val_r;
    return nd;
  }

  Node st[8 * MAX];

  void Push(int id) {
    if (st[id].lzy_set == inf) {
      st[id * 2].val_l += st[id].lzy_add;
      st[id * 2].val_r += st[id].lzy_add;
      st[id * 2 + 1].val_l += st[id].lzy_add;
      st[id * 2 + 1].val_r += st[id].lzy_add;
      st[id * 2].lzy_add += st[id].lzy_add;
      st[id * 2 + 1].lzy_add += st[id].lzy_add;
      st[id].lzy_add = 0;
    } else {
      st[id * 2].val_l = st[id].lzy_set + st[id].lzy_add;
      st[id * 2].val_r = st[id].lzy_set + st[id].lzy_add;
      st[id * 2 + 1].val_l = st[id].lzy_set + st[id].lzy_add;
      st[id * 2 + 1].val_r = st[id].lzy_set + st[id].lzy_add;
      st[id * 2].lzy_set = st[id].lzy_set;
      st[id * 2].lzy_add = st[id].lzy_add;
      st[id * 2 + 1].lzy_set = st[id].lzy_set;
      st[id * 2 + 1].lzy_add = st[id].lzy_add;
      st[id * 2].mx = st[id * 2].mx_l = st[id * 2].mx_r = st[id * 2].len;
      st[id * 2 + 1].mx = st[id * 2 + 1].mx_l = st[id * 2 + 1].mx_r = st[id * 2 + 1].len;
      st[id].lzy_set = inf;
      st[id].lzy_add = 0;
    }
  }

  void Build(int id, int l, int r) {
    if (l == r) {    
      st[id].val_l = st[id].val_r = 0;
      st[id].len = 1;
      st[id].mx = st[id].mx_l = st[id].mx_r = 1;
      return;
    }
    int mid = (l + r) >> 1;
    Build(id * 2, l, mid);
    Build(id * 2 + 1, mid + 1, r);
    st[id] = Merge(st[id * 2], st[id * 2 + 1]);
  }

  void Set(int id, int l, int r, int ll, int rr, long long x) {
    if (ll <= l && r <= rr) {
      st[id].mx = st[id].mx_l = st[id].mx_r = st[id].len;
      st[id].val_l = x;
      st[id].val_r = x;
      st[id].lzy_set = x;
      st[id].lzy_add = 0;
      Push(id);
      return;
    }
    Push(id);
    int mid = (l + r) >> 1;
    if (rr <= mid) {
      Set(id * 2, l, mid, ll, rr, x);
    } else if (ll > mid) {
      Set(id * 2 + 1, mid + 1, r, ll, rr, x);
    } else {
      Set(id * 2, l, mid, ll, rr, x);
      Set(id * 2 + 1, mid + 1, r, ll, rr, x);
    }
    st[id] = Merge(st[id * 2], st[id * 2 + 1]);
  }

  void Add(int id, int l, int r, int ll, int rr, long long x) {
    if (ll <= l && r <= rr) {
      st[id].val_l += x;
      st[id].val_r += x;
      st[id].lzy_add += x;
      Push(id);
      return;
    }
    Push(id);
    int mid = (l + r) >> 1;
    if (rr <= mid) {
      Add(id * 2, l, mid, ll, rr, x);
    } else if (ll > mid) {
      Add(id * 2 + 1, mid + 1, r, ll, rr, x);
    } else {
      Add(id * 2, l, mid, ll, rr, x);
      Add(id * 2 + 1, mid + 1, r, ll, rr, x);
    }
    st[id] = Merge(st[id * 2], st[id * 2 + 1]);
  }

  Node Query(int id, int l, int r, int ll, int rr) {
    if (ll <= l && r <= rr) {
      return st[id];
    }
    Push(id);
    int mid = (l + r) >> 1;
    Node ret;
    if (rr <= mid) {
      ret = Query(id * 2, l, mid, ll, rr);
    } else if (ll > mid) {
      ret = Query(id * 2 + 1, mid + 1, r, ll, rr);
    } else {
      ret = Merge(Query(id * 2, l, mid, ll, rr), Query(id * 2 + 1, mid + 1, r, ll, rr));
    }
    st[id] = Merge(st[id * 2], st[id * 2 + 1]);
    return ret;
  }
} st;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    val.Modify(1, 0, n - 1, i, i, d, 0);
  }
  val.n = n;
  st.Build(1, 0, n - 1);
  for (int i = 0; i + 1 < n; i++) {
    st.Set(1, 0, n - 1, i, i, val.Get(i) - val.Get(i + 1));
  }
  while (q--) {
    int op;
    cin >> op;
    if (op == 1) {
      int l, r, s, c;
      cin >> l >> r >> s >> c;
      --l; --r;
      val.Modify(1, 0, n - 1, l, r, s - c * 1LL * l, c);
      if (l < r) {
        st.Add(1, 0, n - 1, l, r - 1, -c);
      } 
      if (l > 0) {
        st.Set(1, 0, n - 1, l - 1, l - 1, val.Get(l - 1) - val.Get(l));
      } 
      if (r + 1 < n) {
        st.Set(1, 0, n - 1, r, r, val.Get(r) - val.Get(r + 1));
      } 
    }
    if (op == 2) {

    }
    if (op == 3) {
      int l, r;
      cin >> l >> r;
      --l; --r;
      if (l == r) {
        cout << 1 << '\n';
      } else {
        cout << st.Query(1, 0, n - 1, l, r - 1).mx + 1 << '\n';
      }
    }
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3089 ms 154480 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 150700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 382 ms 155064 KB Output is correct
2 Correct 88 ms 152664 KB Output is correct
3 Correct 85 ms 152660 KB Output is correct
4 Correct 81 ms 152528 KB Output is correct
5 Correct 108 ms 152652 KB Output is correct
6 Correct 84 ms 152728 KB Output is correct
7 Correct 85 ms 152660 KB Output is correct
8 Correct 26 ms 150876 KB Output is correct
9 Correct 26 ms 150744 KB Output is correct
10 Correct 28 ms 150876 KB Output is correct
11 Correct 342 ms 154484 KB Output is correct
12 Correct 349 ms 155220 KB Output is correct
13 Correct 338 ms 154452 KB Output is correct
14 Correct 350 ms 154656 KB Output is correct
15 Correct 351 ms 155224 KB Output is correct
16 Correct 336 ms 155472 KB Output is correct
17 Correct 361 ms 155632 KB Output is correct
18 Correct 334 ms 155472 KB Output is correct
19 Correct 322 ms 154704 KB Output is correct
20 Correct 330 ms 154784 KB Output is correct
21 Correct 328 ms 154732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 371 ms 308820 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 382 ms 155064 KB Output is correct
2 Correct 88 ms 152664 KB Output is correct
3 Correct 85 ms 152660 KB Output is correct
4 Correct 81 ms 152528 KB Output is correct
5 Correct 108 ms 152652 KB Output is correct
6 Correct 84 ms 152728 KB Output is correct
7 Correct 85 ms 152660 KB Output is correct
8 Correct 26 ms 150876 KB Output is correct
9 Correct 26 ms 150744 KB Output is correct
10 Correct 28 ms 150876 KB Output is correct
11 Correct 342 ms 154484 KB Output is correct
12 Correct 349 ms 155220 KB Output is correct
13 Correct 338 ms 154452 KB Output is correct
14 Correct 350 ms 154656 KB Output is correct
15 Correct 351 ms 155224 KB Output is correct
16 Correct 336 ms 155472 KB Output is correct
17 Correct 361 ms 155632 KB Output is correct
18 Correct 334 ms 155472 KB Output is correct
19 Correct 322 ms 154704 KB Output is correct
20 Correct 330 ms 154784 KB Output is correct
21 Correct 328 ms 154732 KB Output is correct
22 Correct 721 ms 155900 KB Output is correct
23 Correct 127 ms 153936 KB Output is correct
24 Correct 123 ms 153940 KB Output is correct
25 Correct 127 ms 153976 KB Output is correct
26 Correct 122 ms 153936 KB Output is correct
27 Correct 122 ms 153936 KB Output is correct
28 Correct 124 ms 153944 KB Output is correct
29 Correct 28 ms 150876 KB Output is correct
30 Correct 26 ms 150736 KB Output is correct
31 Correct 25 ms 150868 KB Output is correct
32 Correct 757 ms 157264 KB Output is correct
33 Correct 761 ms 160124 KB Output is correct
34 Correct 773 ms 157368 KB Output is correct
35 Correct 802 ms 157272 KB Output is correct
36 Correct 645 ms 157120 KB Output is correct
37 Correct 601 ms 157072 KB Output is correct
38 Correct 568 ms 157216 KB Output is correct
39 Correct 690 ms 160088 KB Output is correct
40 Correct 711 ms 160340 KB Output is correct
41 Correct 703 ms 160080 KB Output is correct
42 Correct 719 ms 160028 KB Output is correct
43 Correct 744 ms 160084 KB Output is correct
44 Correct 687 ms 159960 KB Output is correct
45 Correct 710 ms 160080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3089 ms 154480 KB Time limit exceeded
2 Halted 0 ms 0 KB -