Submission #425149

#TimeUsernameProblemLanguageResultExecution timeMemory
425149mat_vFinancial Report (JOI21_financial)C++14
48 / 100
4035 ms41484 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i)) #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i)) #define mod 998244353 #define xx first #define yy second #define all(a) (a).begin(), (a).end() #define pb push_back #define ll long long #define pii pair<int,int> #define maxn 300005 using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less) mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int br; map<int,int> sl; int n,d; int niz[maxn]; vector<int> poz[maxn]; int dp[maxn]; int desno[maxn]; int seg[maxn]; void update(int node, int l, int r, int poz, int val){ if(l == r){ seg[node] = val; return; } int mid = (l + r) / 2; if(poz <= mid)update(node * 2, l, mid, poz, val); else update(node * 2 + 1, mid + 1, r, poz, val); seg[node] = max(seg[node * 2], seg[node * 2 + 1]); } int query(int node, int l, int r, int levo, int desno){ if(l > r || levo > desno || levo > r || l > desno)return 0; if(l >= levo && r <= desno)return seg[node]; int mid = (l + r) / 2; return max(query(node * 2, l, mid, levo, desno), query(node * 2 + 1, mid + 1, r, levo, desno)); } /// int segd[4 * maxn]; int lejzi[4 * maxn]; void propagate(int node, int l, int r){ if(lejzi[node] == 0)return; segd[node] += lejzi[node]; if(l != r){ lejzi[node * 2] += lejzi[node]; lejzi[node * 2 + 1] += lejzi[node]; } lejzi[node] = 0; } void initdesno(int node, int l, int r){ if(l == r){ segd[node] = desno[l]; return; } int mid = (l + r) / 2; initdesno(node * 2, l, mid); initdesno(node * 2 + 1, mid + 1, r); segd[node] = max(segd[node * 2], segd[node * 2 + 1]); } void apdejtd(int node, int l, int r, int levo, int desno, int val){ propagate(node, l, r); if(l > r || levo > desno || levo > r || l > desno)return; if(l >= levo && r <= desno){ lejzi[node] += val; propagate(node, l, r); return; } int mid = (l + r) / 2; apdejtd(node * 2, l, mid, levo, desno, val); apdejtd(node * 2 + 1, mid + 1, r, levo, desno, val); segd[node] = max(segd[node * 2], segd[node * 2 + 1]); } int kverid(int node, int l, int r, int levo, int desno){ propagate(node, l, r); if(l > r || levo > desno || levo > r || l > desno)return 0; if(l >= levo && r <= desno)return segd[node]; int mid = (l + r) / 2; return max(kverid(node * 2, l, mid, levo, desno), kverid(node * 2 + 1, mid + 1, r, levo, desno)); } /// int resi(int x){ int l = 1; int r = x-1; while(l < r){ int mid = (l + r) / 2; bool da = 0; if(x - mid <= d){ da = 1; } else{ if(kverid(1,1,n,mid,x-d) < d)da = 1; } if(da)r = mid; else l = mid + 1; } return 1 + query(1,1,n,l,x - 1); } void dodaj(int x){ int sta = kverid(1,1,n,x,x); int r = x; int l = 1; while(l < r){ int mid = (l + r) / 2; int sta2 = kverid(1,1,n,mid,mid); if(sta2 == sta + (x - mid)){ r = mid; } else l = mid + 1; } apdejtd(1,1,n,l,x,-sta); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> d; vector<int> svi; ff(i,1,n){ cin >> niz[i]; svi.pb(niz[i]); } sort(svi.begin(), svi.end()); int last = -1; br = 1; for(auto c:svi){ if(c == last)continue; sl[c] = br; br++; last = c; } ff(i,1,n)niz[i] = sl[niz[i]]; ff(i,1,n){ poz[niz[i]].pb(i); } ff(i,1,n)desno[i] = n-i+1; initdesno(1,1,n); ff(i,1,br-1){ for(auto c:poz[i]){ dp[c] = resi(c); } for(auto c:poz[i]){ dodaj(c); update(1,1,n,c,dp[c]); } } int ans = 0; ff(i,1,n)ans = max(ans, dp[i]); cout << ans << "\n"; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
Main.cpp:140:5: note: in expansion of macro 'ff'
  140 |     ff(i,1,n){
      |     ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
Main.cpp:153:5: note: in expansion of macro 'ff'
  153 |     ff(i,1,n)niz[i] = sl[niz[i]];
      |     ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
Main.cpp:154:5: note: in expansion of macro 'ff'
  154 |     ff(i,1,n){
      |     ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
Main.cpp:158:5: note: in expansion of macro 'ff'
  158 |     ff(i,1,n)desno[i] = n-i+1;
      |     ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
Main.cpp:161:5: note: in expansion of macro 'ff'
  161 |     ff(i,1,br-1){
      |     ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
Main.cpp:171:5: note: in expansion of macro 'ff'
  171 |     ff(i,1,n)ans = max(ans, dp[i]);
      |     ^~
#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...