제출 #1023244

#제출 시각아이디문제언어결과실행 시간메모리
1023244phongFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
469 ms19796 KiB
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define ll long long #define int long long const int nmax = 2e5 + 5; const int lg = 18; const int base = 311; const int M = 5e6; const ll oo = 1e9; const int mod = 987654321; #define fi first #define se second #define endl "\n" #define pii pair<ll, int> using namespace std; int n, q, S, T, a[nmax]; int tree[nmax << 2], lz[nmax << 2]; void build(int id, int l, int r){ if(l == r){ tree[id] = a[l]; return; } int mid = r + l >> 1; build(id << 1, l, mid); build(id << 1 | 1, mid + 1, r); } void fix(int id, int val){ lz[id] += val; tree[id] += val; } void down(int id){ fix(id << 1, lz[id]); fix(id << 1 | 1, lz[id]); lz[id] = 0; } void update(int id, int l, int r, int u, int v, int x){ if(l > v || r < u) return; if(l >= u && r <= v){ return fix(id, x); } down(id); int mid = r + l >> 1; update(id << 1, l, mid, u, v, x); update(id << 1 | 1, mid + 1, r, u, v, x); } #define update(l, r, x) update(1, 0, n, l, r, x) int get(int id, int l, int r, int u){ if(l == r) return tree[id]; down(id); int mid = r + l >> 1; if(u <= mid) return get(id << 1, l, mid, u); return get(id << 1 | 1, mid + 1, r, u); } #define get(u) get(1, 0, n, u) main(){ ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); // freopen("code.inp", "r", stdin); // freopen("code.out", "w", stdout); cin >> n >> q >> S >> T; for(int i = 0; i <= n; ++i) cin >> a[i]; build(1, 0, n); int c1 = 0, c2 = 0; for(int i = 0; i < n; ++i){ if(a[i] < a[i + 1]) c1 += abs(a[i + 1] - a[i]); else c2 += abs(a[i + 1] - a[i]); } // cout << c1 << ' ' << c2 << endl; while(q--){ int l, r, x; cin >> l >> r >> x; if(get(l - 1) < get(l)) c1 -= abs(get(l - 1) - get(l)); else c2 -= abs(get(l - 1) - get(l)); if(r < n){ if(get(r) < get(r + 1)) c1 -= abs(get(r) - get(r + 1)); else c2 -= abs(get(r) - get(r + 1)); } update(l, r, x); if(get(l - 1) < get(l)) c1 += abs(get(l - 1) - get(l)); else c2 += abs(get(l - 1) - get(l)); if(r < n){ if(get(r) < get(r + 1)) c1 += abs(get(r) - get(r + 1)); else c2 += abs(get(r) - get(r + 1)); } // for(int i = 0; i <= n; ++i) cout << get(i) << ' '; // cout << endl; cout << -S *c1 + T * c2 << endl; } } /* 4 -7 5 6 -1 -10 10 -3 6 */

컴파일 시 표준 에러 (stderr) 메시지

foehn_phenomena.cpp: In function 'void build(long long int, long long int, long long int)':
foehn_phenomena.cpp:29:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |     int mid = r + l >> 1;
      |               ~~^~~
foehn_phenomena.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int, long long int)':
foehn_phenomena.cpp:48:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |     int mid = r + l >> 1;
      |               ~~^~~
foehn_phenomena.cpp: In function 'long long int get(long long int, long long int, long long int, long long int)':
foehn_phenomena.cpp:57:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   57 |     int mid = r + l >> 1;
      |               ~~^~~
foehn_phenomena.cpp: At global scope:
foehn_phenomena.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   62 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...