Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************
- Author : Susanka Majumder ( bingobong )
- ***************************************/
- #include<bits/stdc++.h>
- #ifndef ONLINE_JUDGE
- #include<sys/resource.h>
- #include <sys/time.h>
- #endif
- using namespace std;
- /* Template file for Online Algorithmic Competitions */
- /* Typedefs */
- /* System Controllers */
- const long long CPU_TIME = 3 ; // CPU time program has acess to ( in seconds )
- const long long MAX_FILE_SIZE = 1024*1024 ; // Maximum File size that the program can create
- /* Basic types */
- typedef long long ll;
- typedef long double ld;
- typedef unsigned long long ull;
- /* STL containers */
- typedef vector <int> vi;
- typedef vector <ll> vll;
- typedef pair <int, int> pii;
- typedef pair <ll, ll> pll;
- typedef vector < pii > vpii;
- typedef vector < pll > vpll;
- typedef vector <string> vs;
- typedef vector < vi > vvi;
- typedef vector < vll > vvll;
- typedef vector < vpii > vvpii;
- typedef set <int> si;
- /* Macros */
- /* Loops */
- #define fl(i, a, b) for(int i(a); i <= (b); i ++)
- #define rep(i, n) fl(i, 1, (n))
- #define loop(i, n) fl(i, 0, (n) - 1)
- #define rfl(i, a, b) for(int i(a); i >= (b); i --)
- #define rrep(i, n) rfl(i, (n), 1)
- /* Algorithmic functions */
- #define pow2(x) ((x)*(x))
- #define mod(x, m) ((((x) % (m)) + (m)) % (m))
- #define max3(a, b, c) max(a, max(b, c))
- #define min3(a, b, c) min(a, min(b, c))
- #define srt(v) sort((v).begin(), (v).end())
- /* STL container methods */
- #define pb push_back
- #define mp make_pair
- #define eb emplace_back
- /* String methods */
- #define dig(i) (s[i] - '0')
- #define slen(s) s.length()
- /* Shorthand notations */
- #define fr first
- #define sc second
- #define re return
- #define sz(x) ((int) (x).size())
- #define all(x) (x).begin(), (x).end()
- #define sqr(x) ((x) * (x))
- #define fill(x, y) memset(x, y, sizeof(x))
- #define clr(a) fill(a, 0)
- #define endl '\n'
- /* Mathematical */
- #define IINF 0x3f3f3f3f
- #define LLINF 1000111000111000111LL
- #define PI 3.14159265358979323
- #define NIL -1
- /* Debugging purpose */
- #define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
- template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
- template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
- {
- const char* comma = strchr(names + 1, ',');
- std::cerr.write(names, comma - names) << " = " << arg1;
- ZZ(comma, args...);
- }
- /* Fast Input Output */
- #define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
- /* Constants */
- const ll MOD = 1000000007LL;
- const ll MAX = 100010LL;
- /* Templates */
- template<class T> T abs(T x) { re x > 0 ? x : -x; }
- template<typename T> T gcd(T a, T b){ if(b == 0) return a; return gcd(b, a % b); }
- template<typename T> T power(T x, T y, ll m = MOD){T ans = 1; x %= m; while(y > 0){ if(y & 1LL) ans = (ans * x)%m; y >>= 1LL; x = (x*x)%m; } return ans%m; }
- template<typename T> T ceiling(T numerator ,T denominator){ return (numerator+denominator-1)/denominator; }
- template<typename T> T inverse(T num,ll m=MOD){ return ((num==1)?1:(MOD - ((MOD/num)*inverse(MOD%num))%MOD+MOD)%MOD) ; }
- /* input and output of non standard data types */
- template<typename T> istream& operator >> (istream& cin,vector<T> &a){
- for(auto &i:a)cin>>i;
- return cin;
- }
- template<typename T> ostream& operator << (ostream& cout,vector<T> &a){
- for(auto &i:a)cout<<i<<" ";
- return cout;
- }
- template<typename T,typename A> ostream& operator << (ostream& cout,pair<T,A> &a){
- cout<<"("<<a.first<<","<<a.second<<")" ;
- return cout;
- }
- template<typename T> ostream& operator << (ostream& cout,set<T> &a){
- for(auto &i:a)cout<<i<<" ";
- return cout;
- }
- template<typename T,typename A> ostream& operator << (ostream& cout,map<T,A> &a){
- for(auto &i:a) cout<<"("<<i.first<<","<<i.second<<") " ;
- return cout;
- }
- /* additional*/
- #define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
- #define present(c,x) ((c).find(x) != (c).end())
- #define cpresent(c,x) (find(all(c),x) != (c).end())
- /* random genartor */
- // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- // int k = uniform_int_distribution<int>(83, 32832932)(rng) ;
- //double inf = 1.0/0.0;
- #define int long long
- struct segtree
- {
- int size ;
- vector<string> operations ;
- vector<string> values ;
- string NO_OPERATION = "" ;
- string NEUTRAL_ELEMENT = "" ;
- string modify_operation(string a,string b,int len)
- {
- if(b == NO_OPERATION ) return a ;
- srt(b) ;
- return b ;
- }
- string calc_operation(string a,string b){
- string s = a+b ;
- srt(s) ;
- return s ;
- }
- void apply_mod_op(string &a,string b,int len)
- {
- a = modify_operation(a,b,len ) ;
- }
- void init(int n)
- {
- size = 1 ;
- while(size < n ) size *= 2 ;
- operations.assign(2*size , "") ;
- values.assign(2*size , "") ;
- }
- void propagate(int x ,int lx ,int rx)
- {
- if(rx - lx ==1) return ;
- int m = (lx + rx) /2 ;
- apply_mod_op(operations[2*x +1 ] , operations[x] , 1) ;
- apply_mod_op( values[2*x + 1] , operations[x] , m - lx ) ;
- apply_mod_op(operations[2*x+ 2] , operations[x] , 1 ) ;
- apply_mod_op(values[2*x + 2] , operations[x] ,rx - m ) ;
- operations[x] = NO_OPERATION ;
- }
- void modify(int l ,int r ,string v,int x,int lx,int rx)
- {
- propagate(x,lx,rx) ;
- if(lx >= r || l>= rx) return ;
- if(lx >= l && rx<= r )
- {
- apply_mod_op(operations[x] , v, 1) ;
- apply_mod_op(values[x] , v , rx - lx ) ;
- return ;
- }
- int m = (lx+ rx)/2 ;
- modify(l ,r , v , 2*x+1 , lx , m ) ;
- modify( l , r, v , 2*x + 2 , m ,rx ) ;
- values[x] = calc_operation(values[2*x + 1 ], values[2*x + 2] ) ;
- }
- void modify(int l , int r , string v)
- {
- modify(l , r, v , 0 , 0 , size) ;
- }
- string calc(int l ,int r , int x , int lx , int rx)
- {
- propagate(x, lx, rx ) ;
- if( lx>=r || l>= rx ) return NEUTRAL_ELEMENT ;
- if( lx >= l && rx <= r ) return values[x] ;
- int m = ( lx + rx )/2 ;
- auto m1 = calc(l , r , 2*x + 1 , lx , m ) ;
- auto m2 = calc( l , r , 2*x + 2 , m , rx ) ;
- return calc_operation(m1 , m2 ) ;
- }
- string calc(int l,int r){
- return calc(l , r, 0 , 0 , size ) ;
- }
- };
- void solve()
- {
- int n , q ;
- cin>>n>>q ;
- segtree st ;
- st.init(n) ;
- string s ;
- loop(i, n )
- {
- cin>>s ;
- st.modify(i , i + 1 , s) ;
- }
- while(q--)
- {
- int l , r , k ;
- cin>>l>>r>>k ;
- string ans_string = st.calc(l-1 , r) ;
- cout<<ans_string[k-1]<<endl ;
- }
- }
- signed main(){
- #ifndef ONLINE_JUDGE
- (void)!freopen("input.txt","r",stdin);
- (void)!freopen("output.txt","w",stdout);
- (void)!freopen("error.txt","w",stderr);
- /* setting up soft limit on resources */
- rlimit rlim , rlim_time ;
- if(getrlimit( RLIMIT_FSIZE , &rlim) || getrlimit(RLIMIT_CPU , &rlim_time) )
- return 1 ;
- rlim.rlim_cur = MAX_FILE_SIZE ;
- rlim_time.rlim_cur = CPU_TIME ;
- if(setrlimit( RLIMIT_FSIZE , &rlim ) || setrlimit(RLIMIT_CPU , &rlim_time))
- return 2 ;
- #endif
- FAST_IO;
- int t = 1 ;
- //cin>>t ;
- while(t--)
- {
- solve() ;
- }
- #ifndef ONLINE_JUDGE
- cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement