# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
917107 | script_kidd | 원숭이와 사과 나무 (IZhO12_apple) | C++17 | 342 ms | 207956 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("avx2")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
//#define int long long
//#define double long double
//const int INF=2e18;
//#define ll long long
//const int INF=2e9;
using namespace std;
using namespace __gnu_pbds;
using pii=pair<int, int>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
#define FOR(x,n) for(int x=0; x<n; x++)
#define FOR1(x,n) for(int x=1; x<=n; x++)
#define REV(x,n) for(int x=n; x-->0;)
#define REV1(x,n) for(int x=n; x>0; i--)
#define SZ(X) (int)(X.size())
#define pb push_back
#define lb lower_bound
#define mp make_pair
#define all(v) begin(v), end(v)
#define UNTIE_IO ios_base::sync_with_stdio(0);cin.tie(0);
const int MOD=998244353;
const int SIZE=1e9;
int Q;
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
struct Seg {
int l, r, m, sz, val, lz;
Seg* ch[2];
Seg (int _l, int _r): l(_l), r(_r), m((l+r)>>1), sz(r-l+1), val(0), lz(0){
ch[0] = ch[1] = nullptr;
}
void pull(){
val = ch[0]->val + ch[1]->val;
}
void give(int t){
if (t){
lz = t;
val = t*sz;
}
}
void push(){
if (ch[0] == nullptr){
ch[0] = new Seg(l, m);
}
ch[0]->give(lz);
if (ch[1] == nullptr){
ch[1] = new Seg(m+1, r);
}
ch[1]->give(lz);
lz = 0;
}
void upd(int ql, int qr, int x){
if (ql <= l && r <= qr){
give(x);
return;
}
push();
if (ql<=m) ch[0]->upd(ql, qr, x);
if (m<qr) ch[1]->upd(ql, qr, x);
pull();
}
int qry(int ql, int qr){
if (ql <= l && r <= qr){
return val;
}
push();
int res = 0;
if (ql<=m) res += ch[0]->qry(ql, qr);
if (m<qr) res += ch[1]->qry(ql, qr);
return res;
}
};
signed main(){
UNTIE_IO;
Seg rt(1, SIZE);
int C = 0;
cin>>Q;
while (Q--){
int t,l,r;
cin>>t>>l>>r;
if (t==1){
auto res = rt.qry(l+C, r+C);
cout << res << '\n';
C = res;
}
else {
rt.upd(l+C, r+C, 1);
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |