Submission #948126

# Submission time Handle Problem Language Result Execution time Memory
948126 2024-03-17T15:43:58 Z nguyennh Monkey and Apple-trees (IZhO12_apple) C++14
0 / 100
30 ms 32576 KB
#include<bits/stdc++.h>
#define el '\n'
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(int, int, int, int, int, int)':
apple.cpp:32:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |     int mid = l + r >> 1;
      |               ~~^~~
apple.cpp: In member function 'int Segtri::get(int, int, int, int, int)':
apple.cpp:42:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 31576 KB Output is correct
2 Correct 6 ms 31580 KB Output is correct
3 Correct 6 ms 31580 KB Output is correct
4 Correct 12 ms 31832 KB Output is correct
5 Correct 15 ms 31836 KB Output is correct
6 Correct 15 ms 31832 KB Output is correct
7 Correct 14 ms 31836 KB Output is correct
8 Incorrect 30 ms 32576 KB Output isn't correct
9 Halted 0 ms 0 KB -