답안 #885241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885241 2023-12-09T10:22:17 Z raul2008487 Matryoshka (JOI16_matryoshka) C++17
51 / 100
2000 ms 11472 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define mpr make_pair
#define lg(x) __lg(x)
#define bpc(x) __builtin_popcount(x)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int sz = 2e5+5; /// sz is changed
const int mod = 1e9+7;
const ll inf = 10000000000;
void solve(){
    ll n, q, i, j, x, y;
    cin>>n>>q;
    vl a(n), h(n);
    vector<pair<ll,ll>> v;
    for(i=0;i<n;i++){
        cin>>a[i]>>h[i];
        v.pb({a[i], h[i]});
    }
    sort(all(v));
    while(q--){
        cin>>x>>y;
        auto lx = lower_bound(all(v), mpr(x, 0*1LL));
        ll ix = (lx - v.begin());
        multiset<ll> ms;
        vector<pair<ll,ll>> ad;
        for(i = ix; i<n; i++){
            if(v[i].se <= y){
                if(ad.size() && ad.back().fi != v[i].fi){
                    for(j=0;j<ad.size();j++){
                        ms.in(ad[j].se);
                    }
                    ad.clear();
                }
                auto x = ms.lower_bound(v[i].se);
                if(x != ms.begin()){
                    x--;
                    ms.erase(x);
                }
                ad.pb(v[i]);
            }
        }
        for(j=0;j<ad.size();j++){
            ms.in(ad[j].se);
        }
        cout << ms.size() << endl;
    }
 
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //precomp();
    ll tst=1;
    //cin>>tst;
    while(tst--){
        solve();
    }
}
/*
7 3
9 5
3 7
10 6
5 10
2 6
10 10
4 1
10 5
3 5
3 9
*/

Compilation message

matryoshka.cpp: In function 'void solve()':
matryoshka.cpp:37:30: 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]
   37 |                     for(j=0;j<ad.size();j++){
      |                             ~^~~~~~~~~~
matryoshka.cpp:50:18: 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]
   50 |         for(j=0;j<ad.size();j++){
      |                 ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 452 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 452 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 23 ms 348 KB Output is correct
23 Correct 90 ms 600 KB Output is correct
24 Correct 37 ms 604 KB Output is correct
25 Correct 121 ms 612 KB Output is correct
26 Correct 47 ms 600 KB Output is correct
27 Correct 38 ms 616 KB Output is correct
28 Correct 128 ms 600 KB Output is correct
29 Correct 131 ms 580 KB Output is correct
30 Correct 106 ms 344 KB Output is correct
31 Correct 92 ms 852 KB Output is correct
32 Correct 91 ms 604 KB Output is correct
33 Correct 92 ms 600 KB Output is correct
34 Correct 86 ms 604 KB Output is correct
35 Correct 91 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 452 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 23 ms 348 KB Output is correct
23 Correct 90 ms 600 KB Output is correct
24 Correct 37 ms 604 KB Output is correct
25 Correct 121 ms 612 KB Output is correct
26 Correct 47 ms 600 KB Output is correct
27 Correct 38 ms 616 KB Output is correct
28 Correct 128 ms 600 KB Output is correct
29 Correct 131 ms 580 KB Output is correct
30 Correct 106 ms 344 KB Output is correct
31 Correct 92 ms 852 KB Output is correct
32 Correct 91 ms 604 KB Output is correct
33 Correct 92 ms 600 KB Output is correct
34 Correct 86 ms 604 KB Output is correct
35 Correct 91 ms 600 KB Output is correct
36 Execution timed out 2017 ms 11472 KB Time limit exceeded
37 Halted 0 ms 0 KB -