Submission #289726

#TimeUsernameProblemLanguageResultExecution timeMemory
289726eggag32Foehn Phenomena (JOI17_foehn_phenomena)C++17
30 / 100
1088 ms14008 KiB
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pi; #define debug(x) cerr << #x << ": " << x << endl; #define debug2(x, y) debug(x) debug(y); #define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++) #define rep(i, a) for(int i = 0; i < (int)(a); i++) #define all(v) v.begin(), v.end() #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define fi first #define se second const int MAXN = 2e5 + 5; template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); } int n, q; ll s1, t; ll a[MAXN], s[4 * MAXN], lazy[4 * MAXN]; void build(int id = 1, int l = 0, int r = n){ if((r - l) < 2){ s[id] = a[l]; return; } int mid = (l + r) / 2; build(id << 1, l, mid); build((id << 1) + 1, mid, r); s[id] = (s[id << 1] + s[(id << 1) + 1]); } void down(int id, int l, int r){ if(lazy[id]){ s[id] += 1LL * lazy[id] * (r - l); if((r - l) > 1){ lazy[id << 1] += lazy[id]; lazy[(id << 1) + 1] += lazy[id]; } } lazy[id] = 0; } void increase(int x, int y, ll u, int id = 1, int l = 0, int r = n){ //down(id, l, r); if(x >= r || l >= y) return; if(x <= l && r <= y){ lazy[id] += u; down(id, l, r); return; } int mid = (l + r) / 2; increase(x, y, u, id << 1, l, mid); increase(x, y, u, (id << 1) + 1, mid, r); s[id] = (ll)(s[id << 1] + s[(id << 1) + 1]); } ll sum(int x, int y, int id = 1, int l = 0, int r = n){ down(id, l, r); if(x >= r || l >= y) return 0; if(x <= l && r <= y) return (ll)s[id]; int mid = (l + r) / 2; return (ll)(sum(x, y, id * 2, l, mid) + sum(x, y, id * 2 + 1, mid, r)); } int main(){ //freopen("input.in", "r", stdin); //freopen("output.out", "w", stdout); scanf("%d%d%lld%lld", &n, &q, &s1, &t); n++; rep(i, n) scanf("%lld", &a[i]); ll cur = 0; repn(i, 1, n){ if(a[i] > a[i - 1]) cur -= (a[i] - a[i - 1]) * s1; else cur += (a[i - 1] - a[i]) * t; } build(); rep(i, q){ int l, r; ll x; scanf("%d%d%lld", &l, &r, &x); //only need to take care of endpoints if(l > 0){ //reverse the prev if(sum(l, l + 1) > sum(l - 1, l)) cur += (sum(l, l + 1) - sum(l - 1, l)) * s1; else cur -= (sum(l - 1, l) - sum(l, l + 1)) * t; //increase(l, l + 1, x); if((sum(l, l + 1)+x) > sum(l - 1, l)) cur -= ((sum(l, l + 1)+x) - sum(l - 1, l)) * s1; else cur += (sum(l - 1, l) - (sum(l, l + 1)+x)) * t; //increase(l, l + 1, -x); } if(r < (n - 1)){ if(sum(r + 1, r + 2) > sum(r, r + 1)) cur += (sum(r + 1, r + 2) - sum(r, r + 1)) * s1; else cur -= (sum(r, r + 1) - sum(r + 1, r + 2)) * t; //increase(r, r + 1, x); if(sum(r + 1, r + 2) > (sum(r, r + 1)+x)) cur -= (sum(r + 1, r + 2) - (sum(r, r + 1)+x)) * s1; else cur += ((sum(r, r + 1)+x) - sum(r + 1, r + 2)) * t; //increase(r, r + 1, -x); } increase(l, r + 1, x); printf("%lld\n", cur); } return 0; } /* Things to look out for: - Integer overflows - Array bounds - Special cases Be careful! */

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:75:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   75 |  scanf("%d%d%lld%lld", &n, &q, &s1, &t);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:77:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   77 |  rep(i, n) scanf("%lld", &a[i]);
      |            ~~~~~^~~~~~~~~~~~~~~
foehn_phenomena.cpp:87:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   87 |   scanf("%d%d%lld", &l, &r, &x);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...