Submission #256264

#TimeUsernameProblemLanguageResultExecution timeMemory
256264BruteforcemanProgression (NOI20_progression)C++11
15 / 100
32 ms2680 KiB
#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 (stderr)

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);
       ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...