Submission #948127

# Submission time Handle Problem Language Result Execution time Memory
948127 2024-03-17T15:45:09 Z nguyennh Monkey and Apple-trees (IZhO12_apple) C++14
0 / 100
32 ms 63168 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 = 1e6 + 5;

struct Segtri{
  vector<int> st , lazy;
  
  Segtri(int n) : st(4 * n + 5) , lazy(4 * n + 5) {};
  
  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(MN);
  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:33:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |     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:43:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 63068 KB Output is correct
2 Correct 9 ms 63068 KB Output is correct
3 Correct 10 ms 63068 KB Output is correct
4 Correct 16 ms 63068 KB Output is correct
5 Correct 18 ms 63120 KB Output is correct
6 Correct 18 ms 63068 KB Output is correct
7 Correct 19 ms 63132 KB Output is correct
8 Incorrect 32 ms 63168 KB Output isn't correct
9 Halted 0 ms 0 KB -