Submission #427542

#TimeUsernameProblemLanguageResultExecution timeMemory
427542mat_vFinancial Report (JOI21_financial)C++14
48 / 100
338 ms55228 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)); //} /// set<int> s1; set<int> s2; int resi(int x){ int ppp = s1.size(); if(ppp == 0)return 1 + query(1,1,n,1,x - 1); auto it = s1.lower_bound(x); if(it == s1.begin())return 1 + query(1,1,n,1,x - 1); it--; if((*it)+d > x){ if(it == s1.begin())return 1 + query(1,1,n,1,x - 1); it--; } if((*it)+d > x){ if(it == s1.begin())return 1 + query(1,1,n,1,x - 1); it--; } return 1 + query(1,1,n,min((*it)+d-1, x-1), x-1); } void dodaj(int x){ auto it = s1.lower_bound(x); if(it == s1.begin() && (*it) != x)return; if((*it) != x)it--; auto it2 = s2.lower_bound(x); s2.insert(x); int p1 = *it; int p2 = *it2; if(x - p1 < d)s1.erase(p1); if(p2 - (x+1) >= d)s1.insert(x+1); return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> d; s2.insert(0); s2.insert(n+1); 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); s1.insert(1); 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:148:5: note: in expansion of macro 'ff'
  148 |     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:161:5: note: in expansion of macro 'ff'
  161 |     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:162:5: note: in expansion of macro 'ff'
  162 |     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:171:5: note: in expansion of macro 'ff'
  171 |     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:181:5: note: in expansion of macro 'ff'
  181 |     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...