Submission #689654

#TimeUsernameProblemLanguageResultExecution timeMemory
689654zeroesandonesProgression (NOI20_progression)C++17
15 / 100
3087 ms15044 KiB
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef long double ld; typedef vector<ll> vi; typedef pair<ll, ll> pi; #define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i) #define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i) #define nl "\n" #define sp " " #define all(x) (x).begin(), (x).end() #define sc second #define fr first #define pb emplace_back void solve() { ll n, q; cin >> n >> q; ll d[n + 1]; FOR(i, 1, n + 1) { cin >> d[i]; } while(q--) { int t; cin >> t; if(t == 1) { ll l, r, s, c; cin >> l >> r >> s >> c; FOR(i, l, r + 1) { d[i] += (s + (i - l) * c); } } else if(t == 2) { ll l, r, s, c; cin >> l >> r >> s >> c; FOR(i, l, r + 1) { d[i] = (s + (i - l) * c); } } else { ll l, r; cin >> l >> r; // how to test the longest subarray with constant change if(l == r) { cout << 1 << nl; continue; } vi diff; FOR(i, l + 1, r + 1) { diff.pb(d[i] - d[i - 1]); } ll ans = 1, cnt = 1; FOR(i, 1, diff.size()) { if(diff[i] != diff[i - 1]) { cnt = 1; } else { ++cnt; } ans = max(ans, cnt); } cout << (ans + 1) << nl; } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t = 1; // cin >> t; while (t--) { solve(); } }
#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...