답안 #873546

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873546 2023-11-15T09:39:35 Z NintsiChkhaidze Examination (JOI19_examination) C++17
0 / 100
3000 ms 90948 KB
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define left (h<<1),l,((l + r)>>1)
#define right ((h<<1)|1),((l + r)>>1) + 1,r
#define pii pair<int,int>

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
namespace __gnu_pbds{
          typedef tree<long long,
                       null_type,
                       less_equal<long long>,
                       rb_tree_tag,
                       tree_order_statistics_node_update> ordered_set;
}
using namespace __gnu_pbds;

using namespace std;
const int N = 2e5 + 5;

int S[N],T[N],X[N],Y[N],Z[N],ans[N];
map <int,int> mp;
ordered_set v[4*N];

ordered_set merge(ordered_set x, ordered_set y){
    if (x.size() > y.size()) swap(x,y);
    for (int i = 0; i < x.size(); i++)
        y.insert(*(x.find_by_order(i)));
    return y;
}

void upd(int h,int l,int r,int idx,int val){
    if (l == r){
        v[h].insert(val);
        return;
    }

    if (idx > (l + r)/2) upd(right,idx,val);
    else upd(left,idx,val);
    v[h] = merge(v[h*2],v[h*2 + 1]);
}

int get(int h,int l,int r,int L,int R,int k){
    if (r < L || R < l) return 0;
    if (L <= l && r <= R){
        int len = v[h].size();
        return len - v[h].order_of_key(k);
    }
    return get(left,L,R,k) + get(right,L,R,k);
}
signed main (){
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    
    int n,q;
    cin>>n>>q;
    
    vector <int> v1;
    vector <pair<pii,int> > vec;
    for (int i = 1; i <= n; i++){
        cin >> S[i] >> T[i];
        v1.pb(S[i]);
        vec.pb({{S[i] + T[i],2},i});
    }

    for (int i = 1; i <= q; i++){
        cin >> X[i] >> Y[i] >> Z[i];
        v1.pb(X[i]);
        vec.pb({{Z[i],1},i});
    }

    sort(vec.begin(),vec.end());
    sort(v1.begin(),v1.end());

    int val = 0;
    for (int i=0;i<(int)v1.size();i++){
        if (!i || v1[i] != v1[i - 1]) ++val;
        mp[v1[i]] = val;
    }

    for (int i=(int)vec.size()-1;i>=0;i--){
        int id = vec[i].s;
        if (vec[i].f.s == 2){
            upd(1,1,n + q,mp[S[id]],T[id]);
        }else{
            ans[id] = get(1,1,n + q,mp[X[id]],n + q,Y[id]);
        }
    }
    for (int i = 1; i <= q; i++)
        cout<<ans[i]<<endl;
}

Compilation message

examination.cpp: In function '__gnu_pbds::ordered_set merge(__gnu_pbds::ordered_set, __gnu_pbds::ordered_set)':
examination.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and '__gnu_pbds::detail::bin_search_tree_set<long long int, __gnu_pbds::null_type, std::less_equal<long long int>, __gnu_pbds::detail::tree_traits<long long int, __gnu_pbds::null_type, std::less_equal<long long int>, __gnu_pbds::tree_order_statistics_node_update, __gnu_pbds::rb_tree_tag, std::allocator<char> >, std::allocator<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i = 0; i < x.size(); i++)
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 79196 KB Output is correct
2 Correct 41 ms 79412 KB Output is correct
3 Correct 40 ms 79336 KB Output is correct
4 Correct 41 ms 79448 KB Output is correct
5 Correct 41 ms 79188 KB Output is correct
6 Correct 43 ms 79188 KB Output is correct
7 Correct 1771 ms 83528 KB Output is correct
8 Correct 1774 ms 83304 KB Output is correct
9 Correct 1753 ms 83456 KB Output is correct
10 Correct 1357 ms 82996 KB Output is correct
11 Execution timed out 3025 ms 81800 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3024 ms 90948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3024 ms 90948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 79196 KB Output is correct
2 Correct 41 ms 79412 KB Output is correct
3 Correct 40 ms 79336 KB Output is correct
4 Correct 41 ms 79448 KB Output is correct
5 Correct 41 ms 79188 KB Output is correct
6 Correct 43 ms 79188 KB Output is correct
7 Correct 1771 ms 83528 KB Output is correct
8 Correct 1774 ms 83304 KB Output is correct
9 Correct 1753 ms 83456 KB Output is correct
10 Correct 1357 ms 82996 KB Output is correct
11 Execution timed out 3025 ms 81800 KB Time limit exceeded
12 Halted 0 ms 0 KB -