답안 #256264

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

long long getValue(int idx) {
  long long ans = 0;
  for(int i = 1; i <= idx; i++) {
    ans += a[i];
  }
  return ans;
}
void add(int l, int r, long long d) {
  for(int i = l; i <= r; i++) a[i] += d;
}
void assign(int l, int r, long long d) {
  for(int i = l; i <= r; i++) a[i] = d;
}
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));
  }
}
int query(int l, int r) {
  if(l == r) return 1;
  int cnt = 1;
  int ans = 1;
  for(int i = l + 2; i <= r; i++) {
    if(a[i] == a[i - 1]) {
      ++cnt;
      ans = max(ans, cnt);
    } else {
      cnt = 1;
    }
  }
  return ans + 1;
}
int main() {
  int m;
  scanf("%d %d", &n, &m);
  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:52: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:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &arr[i]);
     ~~~~~^~~~~~~~~~~~~~~
Progression.cpp:59: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:61: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:64: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 Execution timed out 31 ms 2680 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 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 Execution timed out 32 ms 2668 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 31 ms 2680 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 32 ms 2668 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 31 ms 2680 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -