Submission #1171528

#TimeUsernameProblemLanguageResultExecution timeMemory
1171528ackhavaInspections (NOI23_inspections)C++20
100 / 100
703 ms35472 KiB
#include <bits/stdc++.h> #define int long long #define REP(v, i, j) for (int v = i; v != j; v++) #define FORI(v) for (auto i : v) #define FORJ(v) for (auto j : v) #define OUT(v, a) \ FORI(v) \ cout << i << a; #define OUTS(v, a, b) \ cout << v.size() << a; \ OUT(v, b) #define in(a, n) \ REP(i, 0, n) \ cin >> a[i]; #define SORT(v) sort(begin(v), end(v)) #define REV(v) reverse(begin(v), end(v)) #define MEMSET(m) memset(m, -1, sizeof m) #define pb push_back #define fi first #define se second #define detachIO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); using namespace std; template<typename _Tp, typename _Alloc = std::allocator<_Tp> > bool operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { if(__x.size() != __y.size()) return false; return std::equal(__x.begin(), __x.end(), __y.begin()); } typedef pair<long long, long long> pii; typedef pair<pii, long long> piii; typedef pair<pii, pii> piiii; set<pair<pii,int>> st; map<int,int> mp; vector<pii> vec; signed main(){ int n,m,q; cin>>n>>m>>q; st.insert({{n+10,0},-10*n}); int time=0; int all=0; REP(i,0,m){ int l,r;cin>>l>>r; auto it = st.lower_bound({{l,-1},-1}); vector<pair<pii,int>> vec; while(it!=st.end() && it->fi.se <=r){ vec.pb(*it); st.erase(it); it = st.lower_bound({{l,-1},-1}); } // FORI(vec)cerr<<" > "<<i.fi.se<<" - "<<i.fi.fi<<": "<<i.se<<endl; FORI(vec){ int vl=i.fi.se; int vr=i.fi.fi; int intersect = min(vr,r) - max(vl,l) + 1; if(i.se>=(-2*n)){ mp[time-l-i.se]+=intersect; all+=intersect; } // r vr if(r<vr){ st.insert({{vr,r+1},i.se}); } // vl l if(vl<l){ st.insert({{l-1,vl},i.se}); } } st.insert({{r,l},time-l}); // FORI(st)cerr<<i.fi.se<<" - "<<i.fi.fi<<": "<<i.se<<endl; // cerr<<endl; time+=r-l+1; } int pref=0; vec.pb({0,0}); FORI(mp){ vec.pb({i.fi,pref+=i.se}); // cerr<<i.fi<<" "<<i.se<<endl; } // int q;cin>>q; while(q--){ int s;cin>>s; int l=0,r=vec.size()-1; int ans=0; while(l<=r){ int mid=(l+r)/2; if(vec[mid].fi<=s)ans=mid,l=mid+1; else r=mid-1; } cout<<(all-vec[ans].se)<<' '; } }
#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...