# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1102321 | thangdz2k7 | Inspections (NOI23_inspections) | C++17 | 290 ms | 34152 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// author : thembululquaUwU
// 3.9.2024
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}
int n, m, q, lo;
set <ii> s;
long long last[N];
vector <pair <long long, int>> e;
void add(long long u, int val){
e.emplace_back(u, val + q);
//cout << lo << ' ' << u << ' ' << val << endl;
}
void solve(){
cin >> n >> m >> q;
s.insert({1, n});
long long timer = 0;
for (lo = 1; lo <= m; ++ lo){
int l, r; cin >> l >> r;
for (auto it = s.lower_bound({l, l}); it != s.end();){
auto [u, v] = *it;
if (u > r) break;
it = s.erase(it);
if (v <= r){
if (last[u])
add(timer + u - l - last[u], v - u + 1);
}
else {
if (last[u]) add(timer + u - l - last[u], r - u + 1);
s.insert({r + 1, v});
if (last[u]) last[r + 1] = last[u] + (r - u + 1);
break;
}
}
last[l] = timer + 1;
s.insert({l, r});
if (l > 1){
auto [u, v] = *(--s.lower_bound({l, l}));
if (v >= l && v <= r){
if (last[u]) add(timer - (last[u] + l - u), v - l + 1);
s.erase({u, v}); s.insert({u, l - 1});
}
else if (v >= l){
if (last[u]) add(timer - (last[u] + l - u), r - l + 1);
s.erase({u, v}); s.insert({u, l - 1}); s.insert({r + 1, v});
if (last[u]) last[r + 1] = last[u] + (r - u + 1);
}
}
timer += (r - l + 1);
}
for (int i = 0; i < q; ++ i){
ll s; cin >> s;
e.emplace_back(s, i);
}
vector <long long> ans(q);
sort(e.begin(), e.end());
reverse(e.begin(), e.end());
long long cur = 0;
for (auto [d, id] : e){
if (id > q) cur += id - q;
else ans[id] = cur;
}
for (long long &f : ans) cout << f << ' ';
}
int main(){
if (fopen("pqh.inp", "r")){
freopen("pqh.inp", "r", stdin);
freopen("pqh.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1; // cin >> t;
while (t --) solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |