Submission #1106342

#TimeUsernameProblemLanguageResultExecution timeMemory
1106342ro9669Inspections (NOI23_inspections)C++17
22 / 100
211 ms23764 KiB
#include <bits/stdc++.h> #define fi first #define se second #define all(v) v.begin() , v.end() #define sz(v) int(v.size()) #define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin()); using namespace std; typedef long long ll; typedef pair<int , int> ii; typedef pair<long long , int> lli; const int maxN = int(2e5)+7; const ll inf = ll(1e18)+7; int n , m , q; set<pair<ii , ll>> st; vector<pair<ll , int>> event; ll query[maxN] , res[maxN]; int id[maxN]; void solve(){ cin >> n >> m >> q; ll t = 0; for (int i = 1 ; i <= m ; i++){ int l , r; cin >> l >> r; while (true){ auto it = st.lower_bound({{l , r} , t}); if (it == st.end()) break; int cur_l = it->fi.fi; int cur_r = it->fi.se; ll cur_t = it->se; if (cur_r > r) break; event.push_back({t + 1ll * (cur_l - l) - cur_t , cur_r - cur_l + 1}); st.erase(it); } set<pair<ii , ll>>::iterator it; st.insert({{l , r} , t}); it = st.find({{l , r} , t}); if (it != st.begin()){ int cur_l = prev(it)->fi.fi; int cur_r = prev(it)->fi.se; ll cur_t = prev(it)->se; if (l <= cur_r && cur_r <= r){ st.erase(prev(it)); event.push_back({t - cur_t - 1ll * (l - cur_l) , cur_r - l + 1}); st.insert({{cur_l , l - 1} , cur_t}); } } it = st.find({{l , r} , t}); if (next(it) != st.end()){ int cur_l = next(it)->fi.fi; int cur_r = next(it)->fi.se; ll cur_t = next(it)->se; if (cur_l <= r && r <= cur_r){ st.erase(next(it)); event.push_back({t + 1ll * (cur_l - l) - cur_t , r - cur_l + 1}); st.insert({{r + 1 , cur_r} , cur_t + 1ll * (r + 1 - cur_l)}); } } it = st.find({{l , r} , t}); if (it != st.begin()){ int cur_l = prev(it)->fi.fi; int cur_r = prev(it)->fi.se; ll cur_t = prev(it)->se; if (cur_l < l && r < cur_r){ st.erase(prev(it)); st.insert({{cur_l , l - 1} , cur_t}); st.insert({{r + 1 , cur_r} , cur_t + 1ll * (r + 1 - cur_l)}); event.push_back({t - cur_t - 1ll * (cur_l - l) , r - l + 1}); } } t += 1ll * (r - l + 1); } for (int i = 1 ; i <= q ; i++){ cin >> query[i]; id[i] = i; } sort(id + 1 , id + q + 1 , [](int x , int y){ return query[x] > query[y]; }); sort(all(event)); reverse(all(event)); ll sum = 0; for (int i = 1 , j = -1 ; i <= q ; i++){ while (j + 1 < sz(event) && event[j + 1].fi > query[id[i]]){ j++; sum += 1ll * event[j].se; } res[id[i]] = sum; } for (int i = 1 ; i <= q ; i++) cout << res[i] << " "; } #define name "A" int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(name".INP" , "r")){ freopen(name".INP" , "r" , stdin); freopen(name".OUT" , "w" , stdout); } int t = 1; //cin >> t; while (t--) solve(); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |         freopen(name".INP" , "r" , stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:101:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |         freopen(name".OUT" , "w" , stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...