Submission #487434

# Submission time Handle Problem Language Result Execution time Memory
487434 2021-11-15T13:26:15 Z urosk Monkey and Apple-trees (IZhO12_apple) C++14
100 / 100
354 ms 146200 KB
//https://oj.uz/problem/view/JOI20_joitter2
// __builtin_popcount(x) broj bitova
// __builtin_popcountll(x)
// __builtin_clz(x) vodece nule
// __builtin_clzll(x)
// __builtin_ctz(x) nule na pocetku
// __builtin_ctzll(x)
// 2000000011
// 2000000033
//#include "bits/stdc++.h"
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll int
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define pi 3.14159265358979323846
#define here cerr<<"---------------------------\n"
#define ceri(a,l,r) {for(ll i = l;i<=r;i++) cerr<<a[i]<< " ";cerr<<endl;}
#define ceri2(a,l,r,n,m) {for(ll i = l;i<=r;i++){for(ll j = n;j<=m;j++) cerr<<a[i][j]<< " ";cerr<<endl;}}
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
    return uniform_int_distribution<ll>(l,r)(rng);
}

void setIO(string inoutname)
{
	freopen((inoutname+".in").c_str(),"r",stdin);
    	freopen((inoutname+".out").c_str(),"w",stdout);
}
#define mod 1
ll gcd(ll a, ll b)
{
   if(b==0) return a;
   if(a==0) return b;
   if(a>=b)  return gcd(a%b,b);
   return  gcd(a,b%a);
}
ll lcm(ll a,ll b){
   return (a/gcd(a,b))*b;
}
ll add(ll a,ll b){
	a+=b;
	a+=mod;
	if(a>=mod) a%=mod;
	return a;
}
ll mul(ll a,ll b){return(a*b)%mod;}
#define mx 1000000000
#define maxn 10000005
ll q;
ll t[maxn];
ll ln[maxn];
ll rn[maxn];
ll lazy[maxn];
ll it = 2;
void push(ll v,ll tl,ll tr){
    if(lazy[v]==0) return;
    t[v] = (tr-tl+1);
    if(tl<tr){
        if(ln[v]==-1) ln[v] = it++;
        if(rn[v]==-1) rn[v] = it++;
        lazy[ln[v]] = 1;
        lazy[rn[v]] = 1;
    }
    lazy[v] = 0;
}
void upd(ll v,ll tl,ll tr,ll l,ll r){
    push(v,tl,tr);
    if(l>r) return;
    if(tl==l&&tr==r){
        lazy[v] = 1;
        push(v,tl,tr);
        return;
    }
    ll mid = (tl+tr)/2;
    if(ln[v]==-1) ln[v] = it++;
    if(rn[v]==-1) rn[v] = it++;
    upd(ln[v],tl,mid,l,min(mid,r));
    upd(rn[v],mid+1,tr,max(mid+1,l),r);
    t[v] = t[ln[v]] + t[rn[v]];
}
ll sum(ll v,ll tl,ll tr,ll l,ll r){
    push(v,tl,tr);
    if(l>r) return 0;
    if(tl==l&&tr==r) return t[v];
    ll mid = (tl+tr)/2;
    ll ans = 0;
    if(ln[v]!=-1) ans+=sum(ln[v],tl,mid,l,min(mid,r));
    if(rn[v]!=-1) ans+=sum(rn[v],mid+1,tr,max(mid+1,l),r);
    return ans;
}
void tc(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
	fill(ln,ln+maxn,-1);
	fill(rn,rn+maxn,-1);
    cin >> q;
    ll c = 0;
    while(q--){
        ll tip,l,r; cin >> tip >> l >> r;
        l+=c;
        r+=c;
        if(tip==1){
            ll ans = sum(1,1,mx,l,r);
            c=ans;
            cout<<ans<<endl;
        }else{
            upd(1,1,mx,l,r);
        }
    }
}
int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
	//setIO("lol");
	int t; t = 1;
	while(t--){
		tc();
	}
	return 0;
}

Compilation message

apple.cpp: In function 'void setIO(std::string)':
apple.cpp:68:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |  freopen((inoutname+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apple.cpp:69:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |      freopen((inoutname+".out").c_str(),"w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 27 ms 78540 KB Output is correct
2 Correct 38 ms 78520 KB Output is correct
3 Correct 36 ms 78600 KB Output is correct
4 Correct 36 ms 79924 KB Output is correct
5 Correct 38 ms 80228 KB Output is correct
6 Correct 46 ms 80140 KB Output is correct
7 Correct 38 ms 80204 KB Output is correct
8 Correct 123 ms 91540 KB Output is correct
9 Correct 258 ms 100648 KB Output is correct
10 Correct 247 ms 103236 KB Output is correct
11 Correct 285 ms 105412 KB Output is correct
12 Correct 300 ms 106308 KB Output is correct
13 Correct 234 ms 113204 KB Output is correct
14 Correct 215 ms 113356 KB Output is correct
15 Correct 354 ms 144132 KB Output is correct
16 Correct 318 ms 144648 KB Output is correct
17 Correct 210 ms 116800 KB Output is correct
18 Correct 202 ms 116732 KB Output is correct
19 Correct 297 ms 146200 KB Output is correct
20 Correct 300 ms 146196 KB Output is correct