답안 #949497

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
949497 2024-03-19T09:46:18 Z nguyennh 원숭이와 사과 나무 (IZhO12_apple) C++14
0 / 100
2000 ms 151000 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 = 1e9 + 5;
 
struct Segtri{
  unordered_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;
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 72 ms 14084 KB Output is correct
5 Correct 92 ms 14824 KB Output is correct
6 Correct 100 ms 14612 KB Output is correct
7 Correct 97 ms 14768 KB Output is correct
8 Correct 1466 ms 117232 KB Output is correct
9 Execution timed out 2052 ms 151000 KB Time limit exceeded
10 Halted 0 ms 0 KB -