Submission #1360784

#TimeUsernameProblemLanguageResultExecution timeMemory
1360784Ahmed_SolymanWall (IOI14_wall)C++20
0 / 100
0 ms344 KiB
/*
In the name of Allah
made by: Ahmed_Solyman
*/
#include <bits/stdc++.h>
#include <ext/rope>

using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define endl "\n"
#define fil(arr,x) memset(arr,x,sizeof(arr))
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
    return (max(a,b)/__gcd(a,b))*min(a,b);
}
struct segtree{
    vector<pair<int,int>>upd;
    int size;
    void init(int n){
        size=n;
        upd.assign(n*3+5,make_pair(0,100000));
    }
    pair<int,int> merge(int l,int r,int i,int j) {
        if (l>=i && r<=j)return make_pair(l,r);
        if (i>=l && j<=r)return make_pair(i,j);
        if (r<i)return make_pair(i,i);
        if (l>j)return make_pair(j,j);
        if (r>i)return make_pair(i,r);
        if (l<j)return make_pair(l,j);
    }
    void set(int l,int r,int p,int lq,int rq,int a,int b){
        if (r<lq || l>rq)return;
        if (l>=lq && r<=rq) {
            upd[p] = merge(a,b,upd[p].first,upd[p].second);
            return;
        }
        int mid=(l+r)/2;
        upd[p*2] = merge(upd[p].first,upd[p].second,upd[p*2].first,upd[p*2].second);
        upd[p*2+1] = merge(upd[p].first,upd[p].second,upd[p*2+1].first,upd[p*2+1].second);
        set(l,mid,p*2,lq,rq,a,b);
        set(mid+1,r,p*2+1,lq,rq,a,b);
    }
    void maximize(int l,int r,int x){
        set(1,size,1,l,r,0,x);
    }
    void minimize(int l,int r,int x){
        set(1,size,1,l,r,x,100000);
    }
    int query(int l,int r,int p,int i){
        if (l==r)return upd[p].first;
        int mid=(l+r)/2;
        upd[p*2] = merge(upd[p].first,upd[p].second,upd[p*2].first,upd[p*2].second);
        upd[p*2+1] = merge(upd[p].first,upd[p].second,upd[p*2+1].first,upd[p*2+1].second);
        if (i<=mid)return query(l,mid,p*2,i);
        else return query(mid+1,r,p*2+1,i);
    }
    int query(int i){
        return query(1,size,1,i);
    }
};

void buildWall(int n, int k, int op[], int left[], int right[],
int height[], int finalHeight[]) {
    segtree sg;
    sg.init(n);
    for (int i=0;i<k;i++) {
        ++left[i]; ++right[i];
        if (op[i]==1) sg.maximize(left[i],right[i],height[i]);
        if (op[i]==2) sg.minimize(left[i],right[i],height[i]);
    }
    for (int i=0;i<n;i++) {
        finalHeight[i]=sg.query(i+1);
    }
}

Compilation message (stderr)

wall.cpp: In member function 'std::pair<int, int> segtree::merge(int, int, int, int)':
wall.cpp:47:5: warning: control reaches end of non-void function [-Wreturn-type]
   47 |     }
      |     ^
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...