Submission #466981

# Submission time Handle Problem Language Result Execution time Memory
466981 2021-08-21T07:06:41 Z Nihal_9936 Monkey and Apple-trees (IZhO12_apple) C++17
0 / 100
2000 ms 103632 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds; 

template <typename num_t>
using ordered_set = tree<num_t, null_type, less<num_t>, rb_tree_tag, tree_order_statistics_node_update>;
 
#ifdef  pikachu
   #include  "welcome_to_python_is_slower_than_c++_club.h"
#else
    #include <bits/stdc++.h>
     using namespace std;
    #define debug(...) 69
#endif
 
 
template<typename T1, typename T2>istream& operator>>(istream& in, pair<T1, T2>& a) { return in >> a.first >> a.second; }
template<typename T1, typename T2>ostream& operator<<(ostream& out, pair<T1, T2> a) { return out << a.first << " " << a.second;}
template<typename T> void print(T t) { cout << t <<' '; }
template<typename T, typename... Args> void print(T t, Args... args) { print(t);print(args...); }
string operator*=(string& s, int cnt) { string t = s;for (size_t i = 1; i < cnt; i++)s += t;return s; }
string operator*(string s, int cnt) { return s *= cnt; }
 
 
#define int               long long 
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define allr(x)           (x).rbegin(),(x).rend()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define len(x)             (int)((x).size())
#define bk                back()
#define elif              else if
#define add               insert
#define append            push_back
#define pop               pop_back 
#define str               string
#define in                :
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define vi                vector<int>
#define vii               vector<pii>
#define mi                map<int,int>
#define mii               map<pii,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define rrep(i,a,b)       for(int i=a;i>b;i--)
#define el                 '\n'
#define printl(arg) cout << arg << endl
// #define print(arg) cout << arg
#define inputa(arg) for (auto& e : arg) cin >> e
#define printa(arg) for (auto& e : arg) print(e);
#define printr(arg) { printl(arg);return; }
#define printd(arg) printf("%0.3lf\n", arg)
 
 
const int mod=1e9+7;
const int INF=1e18;
const int MAX_N= 1e5+10;
const double PI=3.14159265358979323846;

int n,m,k,x,y,z,t,q,counter;

struct chash { /// use most bits rather than just the lowest ones
    const uint64_t C = (int)(2e18*PI)+71; // large odd number
    const int RANDOM = chrono::steady_clock::now().time_since_epoch().count();//rng();
    int operator()(int x) const { /// https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
        return __builtin_bswap64((x^RANDOM)*C); }
};
unordered_map<int, int, chash> s_tree,lazy;
// gp_hash_table<int, int, custom_hash> s_tree,lazy;


// int s_tree[MAX_N*4],lazy[MAX_N*4];
int lazy_def=0;
vi a;
int ans;

int get(int x){
    return s_tree.find(x)!=s_tree.end()?s_tree[x]:0;
}



void solve_lazy(int i_tree,int left ,int right,int vl){
    s_tree[i_tree]=(right-left+1)*vl;
    if(left!=right){
        lazy[i_tree*2]=vl;
        lazy[i_tree*2+1]=vl;
    }
    lazy[i_tree]=lazy_def;

}

void update(int i_tree,int left,int right,int l,int r,int vl){
    if(lazy[i_tree]!=lazy_def){
        solve_lazy(i_tree,left,right,lazy[i_tree]);
    }
    if(right<l or left>r) return;
    if(l<=left and right<=r){
        solve_lazy(i_tree,left,right,vl);
        return;
    }
    int mid=(left+right)/2;
    update(i_tree*2,left,mid,l,r,vl);
    update(i_tree*2+1,mid+1,right,l,r,vl);
    s_tree[i_tree]=get(i_tree*2)+get(i_tree*2+1);
}

void query(int i_tree,int left,int right,int l,int r){
    if(lazy[i_tree]!=lazy_def){
        solve_lazy(i_tree,left,right,lazy[i_tree]);
    }
    if(right<l or left>r) return;
    if(l<=left and right<=r){
        ans+=get(i_tree);
        return;
    }
    int mid=(left+right)/2;
    query(i_tree*2,left,mid,l,r);
    query(i_tree*2+1,mid+1,right,l,r);

}

void code(){
            cin>>n;
            int c=0;
            while(n--){
                cin>>x>>y>>z;

                if(x==1){
                    debug(c);
                    ans=0;
                    query(1,0,1e9+10,y+c,z+c);
                    for(auto& i in s_tree) debug(i);
                    cout<<ans<<el;
                    c=ans;
                }else{
                    // debug(y+c,z+c);
                    update(1,0,1e9+10,y+c,z+c,1);
                }
            }

            

}


signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    // freopen("threesum.in", "r", stdin);
    // freopen("threesum.out", "w", stdout);

    int t = 1;
    // cin>>t;
    while(t--) code();
    return 0;
}

Compilation message

apple.cpp: In function 'std::string operator*=(std::string&, int)':
apple.cpp:24:75: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 | string operator*=(string& s, int cnt) { string t = s;for (size_t i = 1; i < cnt; i++)s += t;return s; }
      |                                                                         ~~^~~~~
apple.cpp: In function 'void code()':
apple.cpp:16:24: warning: statement has no effect [-Wunused-value]
   16 |     #define debug(...) 69
      |                        ^~
apple.cpp:137:21: note: in expansion of macro 'debug'
  137 |                     debug(c);
      |                     ^~~~~
apple.cpp:16:24: warning: statement has no effect [-Wunused-value]
   16 |     #define debug(...) 69
      |                        ^~
apple.cpp:140:44: note: in expansion of macro 'debug'
  140 |                     for(auto& i in s_tree) debug(i);
      |                                            ^~~~~
apple.cpp:140:31: warning: unused variable 'i' [-Wunused-variable]
  140 |                     for(auto& i in s_tree) debug(i);
      |                               ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 275 ms 18436 KB Output is correct
5 Correct 326 ms 20156 KB Output is correct
6 Correct 345 ms 19324 KB Output is correct
7 Correct 372 ms 20084 KB Output is correct
8 Execution timed out 2091 ms 103632 KB Time limit exceeded
9 Halted 0 ms 0 KB -