답안 #1106337

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106337 2024-10-30T02:50:48 Z ro9669 Inspections (NOI23_inspections) C++17
0 / 100
1 ms 2520 KB
#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} , -inf});
            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_r + 1});
            st.erase(it);
        }
        st.insert({{l , r} , t});
        auto 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) continue;
            event.push_back({t - cur_t - 1ll * (l - cur_l) , cur_r - l + 1});
            st.insert({{cur_l , l - 1} , cur_t});
            st.erase(prev(it));
        }
        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) continue;
            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)});
            st.erase(next(it));
        }
        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

Main.cpp: In function 'int main()':
Main.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen(name".INP" , "r" , stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen(name".OUT" , "w" , stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2520 KB Output is correct
3 Incorrect 1 ms 2384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2520 KB Output is correct
3 Incorrect 1 ms 2384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Incorrect 1 ms 2384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2520 KB Output is correct
3 Incorrect 1 ms 2384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2520 KB Output is correct
3 Incorrect 1 ms 2384 KB Output isn't correct
4 Halted 0 ms 0 KB -