답안 #256290

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256290 2020-08-02T13:49:50 Z Bruteforceman Progression (NOI20_progression) C++11
15 / 100
63 ms 71364 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const long long inf = 1e16;
long long a[maxn];
int arr[maxn];
int n;

struct node {
  long long sum, lazyadd, lazyass; 
  long long left, right;
  int pre, suf, opt, sz;
} t[maxn * 4], zero;

void addNode(node &p, long long val) {
  p.left += val;
  p.right += val;
  p.sum += val * p.sz;
  if(p.lazyass == inf) {
    p.lazyadd += val;
  } else {
    p.lazyass += val;
  }
}
void assNode(node &p, long long val) {
  p.left = val;
  p.right = val;
  p.sum = val * p.sz;
  p.opt = p.pre = p.suf = p.sz;
  p.lazyadd = 0;
  p.lazyass = val;
}
void pushdown(int c) {
  int l = c << 1;
  int r = l + 1;
  if(t[c].lazyass == inf) {
    addNode(t[l], t[c].lazyadd);
    addNode(t[r], t[c].lazyadd);
  } else {
    assNode(t[l], t[c].lazyass);
    assNode(t[r], t[c].lazyass);
  }
  t[c].lazyass = inf;
  t[c].lazyadd = 0;
}
void merge(node &ans, node p, node q) {
  ans.sum = p.sum + q.sum;
  ans.left = p.left;
  ans.right = q.right;
  ans.pre = p.pre;
  ans.suf = q.suf;
  ans.opt = max(p.opt, q.opt);
  if(p.pre == p.sz && p.right == q.left) ans.pre += q.pre;
  if(q.suf == q.sz && q.left == p.right) ans.suf += p.suf;
  if(p.right == q.left) ans.opt = max(ans.opt, p.suf + q.pre);
}
void add(int x, int y, long long val, int c = 1, int b = 1, int e = n) {
  if(x <= b && e <= y) {
    addNode(t[c], val);
    return ;
  }
  if(y < b || e < x) return ;
  pushdown(c);
  int m = (b + e) >> 1;
  int l = c << 1;
  int r = l + 1;
  add(x, y, val, l, b, m);
  add(x, y, val, r, m + 1, e);
  merge(t[c], t[l], t[r]);
}
void assign(int x, int y, long long val, int c = 1, int b = 1, int e = n) {
  if(x <= b && e <= y) {
    assNode(t[c], val);
    return ;
  }
  if(y < b || e < x) return ;
  pushdown(c);
  int m = (b + e) >> 1;
  int l = c << 1;
  int r = l + 1;
  assign(x, y, val, l, b, m);
  assign(x, y, val, r, m + 1, e);
  merge(t[c], t[l], t[r]);
}
long long getValue(int idx, int c = 1, int b = 1, int e = n) {
  if(b == e) return t[c].sum;
  pushdown(c);
  int m = (b + e) >> 1;
  int l = c << 1;
  int r = l + 1;
  if(idx <= m) return getValue(idx, l, b, m);
  else return getValue(idx, r, m + 1, e) + t[l].sum;
}
void build(int c = 1, int b = 1, int e = n) {
  t[c].sz = e - b + 1;
  t[c].lazyass = inf;
  t[c].pre = t[c].suf = t[c].opt = t[c].sz;
  if(b == e) {
    return ;
  }
  int m = (b + e) >> 1;
  int l = c << 1;
  int r = l + 1;
  build(l, b, m);
  build(r, m + 1, e);
}
void patch(int l, int r, long long s, long long d) {
  add(l, l, s);
  add(l + 1, r, d);
  if(r + 1 <= n) {
    add(r + 1, r + 1, -(s + (r - l) * d));
  }
}
void rewrite(int l, int r, long long s, long long d) {
  long long last = getValue(r);
  add(l, l, s - getValue(l));
  assign(l + 1, r, d);
  if(r + 1 <= n) {
    add(r + 1, r + 1, last - (s + (r - l) * d));
  }
}
node range(int x, int y, int c = 1, int b = 1, int e = n) {
  if(x <= b && e <= y) {
    return t[c];
  }
  if(y < b || e < x) return zero;
  pushdown(c);
  int m = (b + e) >> 1;
  int l = c << 1;
  int r = l + 1;
  node ans;
  merge(ans, range(x, y, l, b, m), range(x, y, r, m + 1, e));
  return ans;
}
int query(int l, int r) {
  if(l == r) return 1;
  return range(l + 1, r).opt + 1;
}
int main() {
  int m;
  scanf("%d %d", &n, &m);
  build();
  zero.left = -inf; zero.right = inf;
  for(int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
    add(i, i, arr[i] - arr[i - 1]);
  }

  for(int i = 1; i <= m; i++) {
    int c, l, r, s, d;
    scanf("%d %d %d", &c, &l, &r);
    if(c == 1) {
      scanf("%d %d", &s, &d);
      patch(l, r, s, d);
    } else if (c == 2) {
      scanf("%d %d", &s, &d);
      rewrite(l, r, s, d);
    } else {
      printf("%d\n", query(l, r));
    }
  }
  return 0; 
}

Compilation message

Progression.cpp: In function 'int main()':
Progression.cpp:141:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~~
Progression.cpp:145:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &arr[i]);
     ~~~~~^~~~~~~~~~~~~~~
Progression.cpp:151:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &c, &l, &r);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:153:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d", &s, &d);
       ~~~~~^~~~~~~~~~~~~~~~~
Progression.cpp:156:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d", &s, &d);
       ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 60 ms 71288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 61 ms 71288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 63 ms 71364 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 61 ms 71288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 60 ms 71288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -