Submission #424492

#TimeUsernameProblemLanguageResultExecution timeMemory
424492zoooma13Financial Report (JOI21_financial)C++14
100 / 100
799 ms45972 KiB
#include <bits/stdc++.h> using namespace std; struct pref : set <pair<int ,int>>{ void add(int i ,int v){ auto it = insert({i ,v}).first; if(it != begin() && prev(it)->second >= it->second){ erase(it); return; } while(next(it) != end() && next(it)->second <= it->second) erase(next(it)); } int qry(int i){ auto it = upper_bound({i ,-1}); if(it == begin()) return 0; return prev(it)->second; } }; vector <int> par; vector <pref> trac; int fnd(int u){ return par[u] == u? u : par[u] = fnd(par[u]); } int unn(int u ,int v){ u = fnd(u) ,v = fnd(v); if(u == v) return v; if(trac[u].size() > trac[v].size()) swap(u ,v); par[u] = v; for(auto s : trac[u]) trac[v].add(s.first ,s.second); trac[u].clear(); return v; } int main() { int n ,d; scanf("%d%d",&n,&d); vector <int> a(n); for(int&i : a) scanf("%d",&i); vector <int> ord; for(int i = 0; i < n; i++){ ord.push_back(i); par.push_back(i); trac.push_back({}); trac.back().add(i ,1); } sort(ord.begin() ,ord.end() ,[&](int&i ,int&j){ return a[i] == a[j]? i > j : a[i] < a[j]; }); set <int> added; for(int&i : ord){ auto it = added.insert(i).first; if(it != added.begin() && i - *prev(it) <= d){ trac[i].clear(); par[i] = fnd(*prev(it)); trac[par[i]].add(i ,trac[par[i]].qry(i)+1); } if(next(it) != added.end() && *next(it) - i <= d) unn(i ,*next(it)); } printf("%d\n",trac[fnd(0)].qry(n)); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d%d",&n,&d);
      |     ~~~~~^~~~~~~~~~~~~~
Main.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         scanf("%d",&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...