Submission #748732

# Submission time Handle Problem Language Result Execution time Memory
748732 2023-05-26T19:46:48 Z vjudge1 Growing Trees (BOI11_grow) C++17
0 / 100
2 ms 396 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define vi vector<int>
#define ve vector
#define ll long long
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define onbit __builtin_popcount
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
using namespace std;
using namespace __gnu_pbds;
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll MOD = 998244353;
const int nax = 1e6+5;
const int MAX_VAL = 1e6;
double PI=3.14159265359;
int arx[8]={1,1,0,-1,-1,-1, 0, 1};
int ary[8]={0,1,1, 1, 0,-1,-1,-1};
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
vi tab;
int segtree[nax*4][2];
int lazy[nax*4];
void conq(int v) {
    segtree[v*2+1][0] += lazy[v];
    segtree[v*2+1][1] += lazy[v];
    lazy[v*2+1] += lazy[v];
    segtree[v*2+2][0] += lazy[v];
    segtree[v*2+2][1] += lazy[v];
    lazy[v*2+2] += lazy[v];
    lazy[v] = 0;
    //cout<<"3asba"<<endl;
}
void build(int pos,int l,int r){
    if (l>r) return;
    if (l==r){
        segtree[pos][0]=tab[l];
        segtree[pos][1]=tab[l];
        return;
    }
    int mid=(r+l)/2;
    build(pos*2+1,l,mid);
    build(pos*2+2,mid+1,r);
    segtree[pos][0]=max(segtree[pos*2+1][0],segtree[pos*2+2][0]);
    segtree[pos][1]=min(segtree[pos*2+1][1],segtree[pos*2+2][1]);
    return;
}
void update(int pos,int l,int r,int left,int right){
    if (l>r||left>right) return;
    if (l==left&&right==r){
        lazy[pos]++;
        segtree[pos][0]++;
        segtree[pos][1]++;
        return;
    }else{
        conq(pos);
        int mid=(r+l)/2;
        update(pos*2+1,l,mid,left,min(mid,right));
        update(pos*2+2,mid+1,r,max(left,mid+1),right);
        segtree[pos][0]=max(segtree[pos*2+1][0],segtree[pos*2+2][0]);
        segtree[pos][1]=min(segtree[pos*2+1][1],segtree[pos*2+2][1]);
    }
}
int query(int pos,int l,int r,int index){
    if (l>r) return -1e9;
    if (l==r) return l;
    int mid=(r+l)/2;
    conq(pos);
    if (segtree[pos*2+1][0]>=index) return query(pos*2+1,l,mid,index);
    else return query(pos*2+2,mid+1,r,index);
}
int query1(int pos,int l,int r,int index){
    if (l>r) return -1e9;
    if (l==r) return l;
    int mid=(r+l)/2;
    conq(pos);
    //cout << l<<" "<<r<<" "<<segtree[pos*2+2][1]<<endl;
    if (segtree[pos*2+2][1]<=index) return query1(pos*2+2,mid+1,r,index);
    else return query1(pos*2+1,l,mid,index);;
}
int main(){
    optimise;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    //setIO("cowland");
    int n,k;
    cin>>n>>k;
    tab.assign(n,0);
    for (int i = 0; i < n; ++i)
    {
        cin>>tab[i];
    }
    sort(tab.begin(),tab.end());
    build(0,0,n-1);
    while(k--){
        char c;
        cin>>c;
        int x,y;
        cin>>x>>y;
        if (c=='F'){
            int cur=query(0,0,n-1,y);
            //cout << cur<<endl;
            int l=y;
            int r=4*nax;
            while(r-l>1){
                int mid=(r+l)/2;
                int middle=query1(0,0,n-1,mid);
                if (middle-cur+1>x) r=mid;
                else l=mid;
            }
            int cur1=query1(0,0,n-1,l);
            update(0,0,n-1,cur,cur1);
            if (cur1==n-1) continue;
            x-=(cur1-cur+1);
            int h=query1(0,0,n-1,l+1);
            update(0,0,n-1,h-x+1,h);
        }else{
            int l=query(0,0,n-1,x);
            int r=query1(0,0,n-1,y);
            if (segtree[0][0]<x){
                cout << 0<<endl;
                continue;
            }
            //cout<< l<<" "<<r<<endl;
            cout << r-l+1<<endl;
        }
    }
}

   


Compilation message

grow.cpp: In function 'void setIO(std::string)':
grow.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp: In function 'int main()':
grow.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 396 KB Output isn't correct
2 Halted 0 ms 0 KB -