Submission #1041265

# Submission time Handle Problem Language Result Execution time Memory
1041265 2024-08-01T19:53:37 Z pera Examination (JOI19_examination) C++17
43 / 100
1281 ms 516688 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n , q , MAX_S , MAX_T;
vector<int> S(N) , T(N) , X(N) , Y(N) , Z(N) , ans(N);
vector<pair<int , int>> _S , _T;
vector<tuple<int , int , int>> v;
struct node{
   node *left , *right;
   int sum = 0;
   node(int sum = 0) : left(NULL) , right(NULL) , sum(sum) {}
} *t[4 * N];
void UPD(node *&u , int l , int r , int pos , int x){
   if(!u){
      u = new node();
   }
   if(l == r){
      u->sum += x;
      return;
   }
   int m = (l + r) / 2;
   if(pos <= m){
      UPD(u->left , l , m , pos , x);
   }else{
      UPD(u->right , m + 1 , r , pos , x);
   }
   u->sum = 0;
   if(u->left){
      u->sum += u->left->sum;
   }
   if(u->right){
      u->sum += u->right->sum;
   }
}
int GET(node *&u , int l , int r , int L , int R){
   if(l > r || r < L || l > R || u == NULL){
      return 0;
   }
   if(L <= l && r <= R){
      return u->sum;
   }
   int m = (l + r) / 2;
   return GET(u->left , l , m , L , R) + GET(u->right , m + 1 , r , L , R);
}
void update(int u , int l , int r , int pos , int t_pos){
   if(l == r){
      UPD(t[u] , 1 , MAX_T , t_pos , 1);
      return;
   }
   int m = (l + r) / 2;
   if(pos <= m){
      update(u * 2 , l , m , pos , t_pos);
   }else{
      update(u * 2 + 1 , m + 1 , r , pos , t_pos);
   }
   UPD(t[u] , 1 , MAX_T , t_pos , 1);
}
int get(int u , int l , int r , int L , int R , int t_L , int t_R){
   if(l > r || r < L || l > R){
      return 0;
   }
   if(L <= l && r <= R){
      return GET(t[u] , 1 , MAX_T , t_L , t_R);
   }
   int m = (l + r) / 2;
   return get(u * 2 , l , m , L , R , t_L , t_R) + get(u * 2 + 1 , m + 1 , r , L , R , t_L , t_R);
}
int main(){
   cin >> n >> q;
   for(int i = 1;i <= n;i ++){
      cin >> S[i] >> T[i];
      v.push_back({S[i] + T[i] , 1 , i});
      _S.push_back({S[i] , i});
      _T.push_back({T[i] , i});
   }
   for(int i = 1;i <= q;i ++){
      cin >> X[i] >> Y[i] >> Z[i];
      v.push_back({Z[i] , 0 , i});
      _S.push_back({X[i] , -i});
      _T.push_back({Y[i] , -i});
   }
   sort(_S.begin() , _S.end());
   sort(_T.begin() , _T.end());
   for(int i = 0;i < (int)_S.size();i ++){
      int lst = (i > 0 ? _S[i - 1].second > 0 ? S[_S[i - 1].second] : X[-_S[i - 1].second] : 1);
      if(_S[i].second > 0){
         S[_S[i].second] = lst + (i > 0 ? (_S[i].first > _S[i - 1].first) : 0);
      }else{
         X[-_S[i].second] = lst + (i > 0 ? (_S[i].first > _S[i - 1].first) : 0);
      }
   }
   for(int i = 0;i < (int)_T.size();i ++){
      int lst = (i > 0 ? _T[i - 1].second > 0 ? T[_T[i - 1].second] : Y[-_T[i - 1].second] : 1);
      if(_T[i].second > 0){
         T[_T[i].second] = lst + (i > 0 ? (_T[i].first > _T[i - 1].first) : 0);
      }else{
         Y[-_T[i].second] = lst + (i > 0 ? (_T[i].first > _T[i - 1].first) : 0);
      }
   }
   MAX_S = max(*max_element(S.begin() , S.end()) , *max_element(X.begin() , X.end()));
   MAX_T = max(*max_element(T.begin() , T.end()) , *max_element(Y.begin() , Y.end()));
   sort(v.rbegin() , v.rend());
   for(auto [value , type , id] : v){
      if(type > 0){
         update(1 , 1 , MAX_S , S[id] , T[id]);
      }else{
         ans[id] = get(1 , 1 , MAX_S , X[id] , MAX_S , Y[id] , MAX_T);
      }
   }
   for(int i = 1;i <= q;i ++){
      cout << ans[i] << endl;
   }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 21 ms 13824 KB Output is correct
8 Correct 21 ms 13916 KB Output is correct
9 Correct 21 ms 13980 KB Output is correct
10 Correct 13 ms 4700 KB Output is correct
11 Correct 9 ms 4700 KB Output is correct
12 Correct 7 ms 2908 KB Output is correct
13 Correct 22 ms 13916 KB Output is correct
14 Correct 21 ms 13916 KB Output is correct
15 Correct 21 ms 14008 KB Output is correct
16 Correct 10 ms 3416 KB Output is correct
17 Correct 8 ms 3676 KB Output is correct
18 Correct 6 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1222 ms 513972 KB Output is correct
2 Correct 1255 ms 513680 KB Output is correct
3 Correct 1240 ms 514312 KB Output is correct
4 Correct 300 ms 52588 KB Output is correct
5 Correct 292 ms 50280 KB Output is correct
6 Correct 196 ms 9076 KB Output is correct
7 Correct 1115 ms 493416 KB Output is correct
8 Correct 1094 ms 493592 KB Output is correct
9 Correct 1045 ms 471796 KB Output is correct
10 Correct 207 ms 20076 KB Output is correct
11 Correct 212 ms 21608 KB Output is correct
12 Correct 172 ms 9580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1222 ms 513972 KB Output is correct
2 Correct 1255 ms 513680 KB Output is correct
3 Correct 1240 ms 514312 KB Output is correct
4 Correct 300 ms 52588 KB Output is correct
5 Correct 292 ms 50280 KB Output is correct
6 Correct 196 ms 9076 KB Output is correct
7 Correct 1115 ms 493416 KB Output is correct
8 Correct 1094 ms 493592 KB Output is correct
9 Correct 1045 ms 471796 KB Output is correct
10 Correct 207 ms 20076 KB Output is correct
11 Correct 212 ms 21608 KB Output is correct
12 Correct 172 ms 9580 KB Output is correct
13 Correct 1155 ms 516456 KB Output is correct
14 Correct 1260 ms 516688 KB Output is correct
15 Correct 1281 ms 515908 KB Output is correct
16 Correct 287 ms 54256 KB Output is correct
17 Correct 275 ms 52844 KB Output is correct
18 Correct 187 ms 9980 KB Output is correct
19 Correct 1148 ms 516628 KB Output is correct
20 Correct 1184 ms 516460 KB Output is correct
21 Correct 1099 ms 500896 KB Output is correct
22 Correct 218 ms 19456 KB Output is correct
23 Correct 213 ms 21544 KB Output is correct
24 Correct 172 ms 9596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 21 ms 13824 KB Output is correct
8 Correct 21 ms 13916 KB Output is correct
9 Correct 21 ms 13980 KB Output is correct
10 Correct 13 ms 4700 KB Output is correct
11 Correct 9 ms 4700 KB Output is correct
12 Correct 7 ms 2908 KB Output is correct
13 Correct 22 ms 13916 KB Output is correct
14 Correct 21 ms 13916 KB Output is correct
15 Correct 21 ms 14008 KB Output is correct
16 Correct 10 ms 3416 KB Output is correct
17 Correct 8 ms 3676 KB Output is correct
18 Correct 6 ms 2908 KB Output is correct
19 Correct 1222 ms 513972 KB Output is correct
20 Correct 1255 ms 513680 KB Output is correct
21 Correct 1240 ms 514312 KB Output is correct
22 Correct 300 ms 52588 KB Output is correct
23 Correct 292 ms 50280 KB Output is correct
24 Correct 196 ms 9076 KB Output is correct
25 Correct 1115 ms 493416 KB Output is correct
26 Correct 1094 ms 493592 KB Output is correct
27 Correct 1045 ms 471796 KB Output is correct
28 Correct 207 ms 20076 KB Output is correct
29 Correct 212 ms 21608 KB Output is correct
30 Correct 172 ms 9580 KB Output is correct
31 Correct 1155 ms 516456 KB Output is correct
32 Correct 1260 ms 516688 KB Output is correct
33 Correct 1281 ms 515908 KB Output is correct
34 Correct 287 ms 54256 KB Output is correct
35 Correct 275 ms 52844 KB Output is correct
36 Correct 187 ms 9980 KB Output is correct
37 Correct 1148 ms 516628 KB Output is correct
38 Correct 1184 ms 516460 KB Output is correct
39 Correct 1099 ms 500896 KB Output is correct
40 Correct 218 ms 19456 KB Output is correct
41 Correct 213 ms 21544 KB Output is correct
42 Correct 172 ms 9596 KB Output is correct
43 Runtime error 153 ms 22852 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -