제출 #1311580

#제출 시각아이디문제언어결과실행 시간메모리
1311580Zbyszek99Financial Report (JOI21_financial)C++20
100 / 100
447 ms21120 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define ull unsigned long long #define ff first #define ss second #define pii pair<int,int> #define pll pair<long long, long long> #define vi vector<int> #define vl vector<long long> #define pb push_back #define rep(i, b) for(int i = 0; i < (b); ++i) #define rep2(i,a,b) for(int i = a; i <= (b); ++i) #define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c) #define count_bits(x) __builtin_popcountll((x)) #define all(x) (x).begin(),(x).end() #define siz(x) (int)(x).size() #define forall(it,x) for(auto& it:(x)) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; //mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());} //ll los(ll a, ll b) {return a + (mt() % (b-a+1));} const int INF = 1e9+50; const ll INF_L = 1e18+40; const ll MOD = 1e9+7; const int tree_siz = 1024*1024-1; int max_[tree_siz+1]; int get_max(int akt, int p1, int p2, int s1, int s2) { if(p2 < s1 || p1 > s2) return 0; if(p1 >= s1 && p2 <= s2) return max_[akt]; return max(get_max(akt*2,p1,(p1+p2)/2,s1,s2),get_max(akt*2+1,(p1+p2)/2+1,p2,s1,s2)); } void upd(int v) { max_[v] = max(max_[v*2],max_[v*2+1]); if(v != 1) upd(v/2); } void change(int ind, int x) { max_[tree_siz/2+1+ind]+=x; upd((tree_siz/2+1+ind)/2); } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //random_start(); int n,d; cin >> n >> d; set<int> bad_pos; set<int> active; vector<pii> vsort; rep(i,n) { int x; cin >> x; vsort.pb({x,-i}); } sort(all(vsort)); vi X; rep(i,n) X.pb(-vsort[i].ss); int ans = 0; forall(it,X) { int prev_elm = -1; int nxt_elm = -1; auto ptr = active.lower_bound(it); if(ptr != active.end()) nxt_elm = *ptr; if(ptr != active.begin()) prev_elm = *(--ptr); if(it-prev_elm-1 >= d) bad_pos.insert(it); if(nxt_elm != -1 && bad_pos.find(nxt_elm) != bad_pos.end() && nxt_elm-it-1 < d) bad_pos.erase(nxt_elm); int prv = 0; auto prv_ptr = bad_pos.upper_bound(it); if(prv_ptr != bad_pos.begin()) prv = *(--prv_ptr); int dp = get_max(1,0,tree_siz/2,prv,it)+1; ans = max(ans,dp); change(it,dp); active.insert(it); } cout << ans; }
#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...