Submission #949495

# Submission time Handle Problem Language Result Execution time Memory
949495 2024-03-19T09:45:22 Z nguyennh Monkey and Apple-trees (IZhO12_apple) C++14
0 / 100
2000 ms 112236 KB
#include<bits/stdc++.h>
#define el '\n'
#define int long long
using namespace std ;
 
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
 
const int MN = 1e7 + 5;
 
struct Segtri{
  map<int , int> st , lazy;
  
  void fix(int id , int l , int r){
    if (!lazy[id]) return;
    st[id] = r - l + 1;
    if (l != r){
      lazy[id << 1] = lazy[id];
      lazy[id << 1 | 1] = lazy[id];
    }
    lazy[id] = 0;
  }
  
  void update(int id , int l , int r , int u , int v , int val){
    fix(id , l , r);
    if (l > v || r < u) return;
    else if (l >= u && r <= v){
      lazy[id] = val;
      fix(id , l , r);
      return;
    }
    int mid = l + r >> 1;
    update(id << 1 , l , mid , u , v , val);
    update(id << 1 | 1 , mid + 1 , r , u , v , val);
    st[id] = st[id << 1] + st[id << 1 | 1];
  }
  
  int get(int id , int l , int r , int u , int v){
    fix(id , l , r);
    if (l > v || r < u) return 0;
    else if (l >= u && r <= v) return st[id];
    int mid = l + r >> 1;
    return get(id << 1 , l , mid , u , v) + get(id << 1 | 1 , mid + 1 , r , u , v);
  }
};
 
int32_t main (){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int m;
  cin >> m;
  Segtri it;
  int last = 0;
  for ( int i = 1 ; i <= m ; i++ ){
    int type , l , r;
    cin >> type >> l >> r;
    l += last;
    r += last;
    if (type == 1){
      last = it.get(1 , 1 , MN , l , r);
      cout << last << el;
    }
    else {
      it.update(1 , 1 , MN , l , r , 1);
    }
  }
}

Compilation message

apple.cpp: In member function 'void Segtri::update(long long int, long long int, long long int, long long int, long long int, long long int)':
apple.cpp:31:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |     int mid = l + r >> 1;
      |               ~~^~~
apple.cpp: In member function 'long long int Segtri::get(long long int, long long int, long long int, long long int, long long int)':
apple.cpp:41:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 268 ms 17640 KB Output is correct
5 Correct 353 ms 21584 KB Output is correct
6 Correct 351 ms 20484 KB Output is correct
7 Correct 348 ms 21236 KB Output is correct
8 Execution timed out 2048 ms 112236 KB Time limit exceeded
9 Halted 0 ms 0 KB -