Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <iomanip>
- #include <vector>
- #include <map>
- #include <algorithm>
- #include <string>
- #include <cmath>
- #include <set>
- #include <unordered_set>
- #include <stack>
- #include <cassert>
- #include <queue>
- #include <deque>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- //#define int long long
- const int inf=1e9+1329;
- const int len=3;
- int n;
- int ind=1;
- vector<int> blocks;
- vector<int> a;
- vector<pair<int, int>> colors(1);
- void update(int cur,int &to_update){
- to_update=max(cur,to_update);
- }
- void update_block(int cur){
- int l=cur*len;
- for(int i=l;i<l+len;i++){
- update(a[i], blocks[cur]);
- }
- }
- void precalc(){
- while (n%len!=0) {
- n++;
- a.push_back(0);
- }
- blocks.assign(n/len, 0);
- for(int i=0;i<n;i++){
- update(a[i], blocks[i/len]);
- }
- }
- int get_max(int l,int r){
- //полуинтервалы
- int ans=0;
- for(int i=l;i<r;){
- if(i%len==0 && i+len<r){
- update(blocks[i/len], ans);
- i+=len;
- }
- else{
- update(a[i], ans);
- i++;
- }
- }
- return ans;
- }
- void modify(int l,int r,int val){
- //полуинтервал
- for(int i=l;i<r;){
- if(i%len==0 && i+len<r){
- blocks[i/len]=val;
- i+=len;
- }
- else{
- a[i]=val;
- i++;
- }
- }
- if(l%len!=0){
- update_block(l/len);
- }
- if((r-1)%len!=0){
- update_block((r-1)/len);
- }
- }
- /*void query_merge(int l,int r){
- auto mx=get_max(l, r);
- if(mx!=0){
- cout << "0\n";
- return;
- }
- cout << "1\n";
- colors.push_back({l,r-1}); //включительно!!!!!!
- modify(l, r, ind);
- ind++;
- }
- void query_split(int pos){
- int cur_color=get_max(pos, pos+1);
- if(cur_color==0){
- cout << "0 0\n";
- return;
- }
- int l=colors[cur_color].first;
- int r=colors[cur_color].second;
- if(l==-1 && r==-1){
- cout << "0 0\n";
- return;
- }
- cout << l+1 << " " << r+1 << "\n";
- modify(l, r+1, 0);
- colors[cur_color]={-1,-1};
- }*/
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- cin >> n;
- a.resize(n,0);
- precalc();
- /*int q;
- cin >> q;
- while (q--) {
- int tp;
- cin >> tp;
- if(tp==1){
- int l,r;
- cin >> l >> r;
- l--;
- query_merge(l, r);
- }
- else{
- int pos;
- cin >> pos;
- pos--;
- query_split(pos);
- }
- }*/
- modify(0, 5, 1);
- cout << get_max(1, 2) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement