제출 #1321321

#제출 시각아이디문제언어결과실행 시간메모리
132132112345678Inspections (NOI23_inspections)C++17
100 / 100
298 ms22876 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll nx=2e5+5; ll n, m, q, l, r, s, t, x; // t=currenttime vector<pair<ll, ll>> ins; map<ll, pair<ll, ll>> mp; // key = r, value = {l, last_value} void split(ll x) // split x, x+1 ออกเป็นสองช่วง { if (!x) return; // x = 0 auto itr=mp.lower_bound(x); // หาช่วงที่คลุม x int oldl=itr->second.first, oldr=itr->first, oldvalue=itr->second.second; if (oldr==x) return; // rightmost of the range is indeed x mp[x]={oldl, itr->second.second-(itr->first-x)}; // new range with the rightmost position as x itr->second.first=x+1; // แก้ช่วงเดิม (ขอบซ้ายของช่วงเดิม) } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>m>>q; mp[n]={1, -1e18}; for (int i=1; i<=m; i++) { cin>>l>>r; split(l-1); // split l-1 and l split(r); // ไล่ทุกช่วงที่อยู่ใน range (l, r) for (auto itr=mp.lower_bound(l); itr!=mp.end()&&itr->first<=r; itr=mp.erase(itr)) // mp.erase() return the next iterator { // itr แต่ละบล้อคที่จะลบทิ้ง ll curl=itr->second.first, curr=itr->first, curend=itr->second.second; ll sz=curr-curl+1; t+=sz; // t=ending time of current block we're considering ins.push_back({t-curend, sz}); // {value, amount that we got} } // total running time <= amount time we add range into map (3*m) mp[r]={l, t}; // add new range } sort(ins.begin(), ins.end()); for (int i=0; i<ins.size(); i++) if (ins[i].first>=1e18) ins[i].second=0; for (int i=(int)ins.size()-2; i>=0; i--) ins[i].second+=ins[i+1].second; for (int i=1; i<=q; i++) { cin>>x; // หา sum of ins[].second that ins[].first>x auto itr=upper_bound(ins.begin(), ins.end(), make_pair(x, LLONG_MAX)); cout<<itr->second<<' '; } }
#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...