답안 #1107380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107380 2024-11-01T07:27:03 Z 12345678 Inspections (NOI23_inspections) C++17
100 / 100
238 ms 38056 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

struct interval
{
    ll l, r, x;
    interval(ll l, ll r, ll x): l(l), r(r), x(x) {}
    bool operator<(const interval &o) const {return l<o.l;}
};

const int nx=2e5+5;

ll n, m, q, l, r, t, sf[nx], res[nx], cur, sm, idx;
set<interval> s;
vector<pair<ll, ll>> v, qrs;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m>>q;
    s.insert(interval(1, n, -1e18));
    for (int i=1; i<=m; i++)
    {
        cin>>l>>r;
        auto itr=prev(s.upper_bound(interval(l, 0, 0)));
        auto tmp=interval(*itr);
        s.erase(itr);
        if (itr->r>=r)
        {
            v.push_back({t-(tmp.x+l-tmp.l), r-l+1});
            if (tmp.l<l) s.insert(interval(tmp.l, l-1, tmp.x));
            s.insert(interval(l, r, t));
            if (r<tmp.r) s.insert(interval(r+1, tmp.r, tmp.x+r+1-tmp.l));
            t+=r-l+1;
            //cout<<"after "<<i<<' '<<"added "<<l<<' '<<r<<'\n';
            //for (auto x:s) cout<<x.l<<' '<<x.r<<' '<<x.x<<'\n';
            continue;
        }
        else
        {
            v.push_back({t-(tmp.x+l-tmp.l), tmp.r-l+1});
            if (tmp.l<l) s.insert(interval(tmp.l, l-1, tmp.x));
        }
        itr=s.lower_bound(interval(l, 0, 0));
        while (itr!=s.end()&&itr->l<=r)
        {
            if (itr->r<=r)
            {
                v.push_back({t+itr->l-l-itr->x, itr->r-itr->l+1});
                itr=s.erase(itr);
            }
            else
            {
                v.push_back({t+itr->l-l-itr->x, r-itr->l+1});
                if (r<itr->r) s.insert(interval(r+1, itr->r, itr->x+r-itr->l+1));
                s.erase(itr);
                break;
            }
        }
        s.insert(interval(l, r, t));
        t+=r-l+1;
        //cout<<"after "<<i<<' '<<"added "<<l<<' '<<r<<'\n';
        //for (auto x:s) cout<<x.l<<' '<<x.r<<' '<<x.x<<'\n';
    }
    //for (auto x:v) cout<<x.first<<' '<<x.second<<'\n';
    sort(v.begin(), v.end());
    for (auto x:v) if (x.first<1e17) sm+=x.second;
    for (int i=1; i<=q; i++) cin>>sf[i], qrs.push_back({sf[i], i});
    sort(qrs.begin(), qrs.end());
    for (int i=0; i<q; i++)
    {
        while (idx<v.size()&&v[idx].first<=qrs[i].first) sm-=v[idx].second, idx++;
        res[qrs[i].second]=sm;
    }
    for (int i=1; i<=q; i++) cout<<res[i]<<' ';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:75:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |         while (idx<v.size()&&v[idx].first<=qrs[i].first) sm-=v[idx].second, idx++;
      |                ~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2552 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2552 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 47 ms 10500 KB Output is correct
14 Correct 39 ms 10468 KB Output is correct
15 Correct 41 ms 10500 KB Output is correct
16 Correct 42 ms 10432 KB Output is correct
17 Correct 47 ms 10500 KB Output is correct
18 Correct 45 ms 10176 KB Output is correct
19 Correct 48 ms 10396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 49 ms 10296 KB Output is correct
4 Correct 44 ms 10432 KB Output is correct
5 Correct 111 ms 24508 KB Output is correct
6 Correct 114 ms 23988 KB Output is correct
7 Correct 96 ms 16972 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2552 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 47 ms 10500 KB Output is correct
14 Correct 39 ms 10468 KB Output is correct
15 Correct 41 ms 10500 KB Output is correct
16 Correct 42 ms 10432 KB Output is correct
17 Correct 47 ms 10500 KB Output is correct
18 Correct 45 ms 10176 KB Output is correct
19 Correct 48 ms 10396 KB Output is correct
20 Correct 46 ms 10904 KB Output is correct
21 Correct 42 ms 10176 KB Output is correct
22 Correct 40 ms 11008 KB Output is correct
23 Correct 40 ms 10436 KB Output is correct
24 Correct 43 ms 10480 KB Output is correct
25 Correct 45 ms 10432 KB Output is correct
26 Correct 42 ms 10948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2552 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 47 ms 10500 KB Output is correct
14 Correct 39 ms 10468 KB Output is correct
15 Correct 41 ms 10500 KB Output is correct
16 Correct 42 ms 10432 KB Output is correct
17 Correct 47 ms 10500 KB Output is correct
18 Correct 45 ms 10176 KB Output is correct
19 Correct 48 ms 10396 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 49 ms 10296 KB Output is correct
23 Correct 44 ms 10432 KB Output is correct
24 Correct 111 ms 24508 KB Output is correct
25 Correct 114 ms 23988 KB Output is correct
26 Correct 96 ms 16972 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 46 ms 10904 KB Output is correct
30 Correct 42 ms 10176 KB Output is correct
31 Correct 40 ms 11008 KB Output is correct
32 Correct 40 ms 10436 KB Output is correct
33 Correct 43 ms 10480 KB Output is correct
34 Correct 45 ms 10432 KB Output is correct
35 Correct 42 ms 10948 KB Output is correct
36 Correct 170 ms 26464 KB Output is correct
37 Correct 160 ms 26816 KB Output is correct
38 Correct 161 ms 26588 KB Output is correct
39 Correct 129 ms 24232 KB Output is correct
40 Correct 154 ms 26284 KB Output is correct
41 Correct 198 ms 31016 KB Output is correct
42 Correct 200 ms 32416 KB Output is correct
43 Correct 216 ms 38056 KB Output is correct
44 Correct 238 ms 36760 KB Output is correct
45 Correct 178 ms 25944 KB Output is correct
46 Correct 214 ms 25952 KB Output is correct
47 Correct 220 ms 26280 KB Output is correct
48 Correct 154 ms 26876 KB Output is correct