Submission #1112860

# Submission time Handle Problem Language Result Execution time Memory
1112860 2024-11-15T04:22:21 Z Roumak77 Inspections (NOI23_inspections) C++17
29 / 100
2000 ms 14792 KB
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <limits>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
using namespace std;

using ll = long long;

void solve(){

    ll n, m, q;
    cin >> n >> m >> q;
    ll curr = 0;
    vector<ll> total;
    vector<vector<ll>> list_n(n, vector<ll>{});
    vector<pair<ll, ll>> inp;

    /*for(ll i = 0; i < m; i++){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        for(ll j = a; j <= b; j++){
            list_n[j].push_back(j - a + curr);
        }
        curr += b - a + 1;
    }*/

    for(ll i = 0; i < m; i++){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        inp.push_back({a, b});
    }

    vector<ll> ans(q, 0);
    vector<pair<ll, ll>> queries(q, {0, 0});
    vector<ll> diff_arr(q, 0);

    /*for(ll i = 0; i < n; i++){
        if(list_n[i].empty()){
            continue;
        }
        sort(list_n[i].begin(), list_n[i].end());
        for(ll j = 0; j < list_n[i].size() - 1; j++){
            //cout << j << " " << list_n[i].size() << endl;
            total.push_back(list_n[i][j + 1] - list_n[i][j]);
        }
    }

    sort(total.begin(), total.end());

    for(ll i = 0; i < q; i++){
        ll temp;
        cin >> temp;


        ll l = -1;
        ll r = total.size();


        while(l + 1 < r){
            ll mid = (l + r)/2;

            if(total[mid] > temp){
                r = mid;
            }else{
                l = mid;
            }
        }

        cout << total.size() - r << " ";

    }*/




    for(ll i = 0; i < q; i++){
        cin >> queries[i].first;
        queries[i].second = i;
    }

    sort(queries.rbegin(), queries.rend());

    vector<ll> last(n, -1);
    curr = 0;
    for(ll i = 0; i < m; i++){
        ll a = inp[i].first, b = inp[i].second;

        for(ll j = a; j <= b; j++){
            ll time = j - a + curr;
            if(last[j] == -1){
                last[j] = time;
            }else{

                ll diff = time - last[j] - 1;

                ll l = -1, r = q - 1;
                if(queries[r].first <= diff){
                    while(l + 1 < r){
                        ll mid = (l + r)/2;
                        if(queries[mid].first <= diff){
                            r = mid;
                        }else{
                            l = mid;
                        }
                    }
                    diff_arr[r]++;
                }


                last[j] = time;
            }
        }
        curr += b - a + 1;
    }

    curr = 0;
    for(ll i = 0; i < q; i++){
        curr += diff_arr[i];
        queries[i].first = curr;
    }
    for(ll i = 0; i < q; i++){
        ans[queries[i].second] = queries[i].first;
    }
    for(ll i = 0; i < q; i++){
        cout << ans[i] << " ";
    }


}

bool single = true;

int main(){

    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);

    ll t = 1;
    if(!single) cin >> t;

    while(t--){
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 70 ms 8600 KB Output is correct
14 Correct 40 ms 8520 KB Output is correct
15 Correct 84 ms 8520 KB Output is correct
16 Correct 84 ms 8776 KB Output is correct
17 Correct 43 ms 8520 KB Output is correct
18 Correct 87 ms 8520 KB Output is correct
19 Correct 79 ms 8780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 86 ms 8520 KB Output is correct
4 Execution timed out 2067 ms 14792 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 70 ms 8600 KB Output is correct
14 Correct 40 ms 8520 KB Output is correct
15 Correct 84 ms 8520 KB Output is correct
16 Correct 84 ms 8776 KB Output is correct
17 Correct 43 ms 8520 KB Output is correct
18 Correct 87 ms 8520 KB Output is correct
19 Correct 79 ms 8780 KB Output is correct
20 Execution timed out 2051 ms 14408 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 70 ms 8600 KB Output is correct
14 Correct 40 ms 8520 KB Output is correct
15 Correct 84 ms 8520 KB Output is correct
16 Correct 84 ms 8776 KB Output is correct
17 Correct 43 ms 8520 KB Output is correct
18 Correct 87 ms 8520 KB Output is correct
19 Correct 79 ms 8780 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 86 ms 8520 KB Output is correct
23 Execution timed out 2067 ms 14792 KB Time limit exceeded
24 Halted 0 ms 0 KB -