Submission #424048

#TimeUsernameProblemLanguageResultExecution timeMemory
424048SAADWall (IOI14_wall)C++17
0 / 100
2 ms4172 KiB
#define F first
#define S second
#define rep(i,a,b) for(int i=a;!(a==b&&i!=b)&&((i<=b&&b>=a)||(i>=b&&a>=b));i+=(a<=b?1:-1))
#define pb push_back
#define Fbitl __builtin_ffs
#define bit1 __builtin_popcount
//#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
//#include "wall.h"
bool th ;
int seg[(int)1e6 + 1] , L , R , num ;
int n ;
void segmant ( int idx ) {
    if (idx >= n) return;
    int l = bit1(idx)-1 , r = l + (n/pow(2,(int)(log2(idx)))) - 1;
    if ( l >= L && r <= R ) {
        if ( th ) seg[idx] = (seg[idx]==-1?num:min(seg[idx],num));
        else seg[idx] = (seg[idx]==-1?num:max(seg[idx],num));
    }
    else if ( l > R || r < L ) return;
    else {
        segmant(idx*2);
        segmant((idx*2)+1);
    }
}
int mx ( int idx ) {
    if (idx==1) return seg[1];
    int res = max(seg[idx],mx(idx/2));
    return res;
}
int mn ( int idx ) {
    if (idx==1) return (seg[1]==-1?(int)1e6:seg[1]);
    int res = min((seg[idx]==-1?(int)1e6:seg[idx]),mn(idx/2));
    return res;
}

void buildWall(int n, int k, int op[], int left[], int right[],int height[], int finalHeight[]) {
    //memset(seg,-1,sizeof(-1));
    //for (int i=n;i<n+n;i++) seg[i] = 0;
    ::n = n;
    int c = 0;
    while (op[c] == 1 && c < k) {
        num = height[c];L = left[c];R = right[c];
        segmant(1);
        c++;
    }
    for (int i=0;i<n;i++) finalHeight[i] = mx(i+n);
    memset(seg,-1,sizeof(seg));
    th = true;
    while (op[c] == 2 && c < k) {
        num = height[c];L = left[c];R = right[c];
        segmant(1);
        c++;
    }
    for (int i=0;i<n;i++) finalHeight[i] = min(finalHeight[i],mn(i+n));
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...