답안 #747168

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747168 2023-05-23T19:32:30 Z Zflop 벽 (IOI14_wall) C++14
0 / 100
320 ms 8092 KB
#include <bits/stdc++.h>
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
/*
ID: 10002181
LANG: C++
TASK: lamps
*/
 
using str = string; // yay python!
using ld = long double; // or double, if TL is tight
using ll = long long;
using int64 = ll;
using db = double;
using ull = unsigned long long;
 
#define ch() getchar()
#define pc(x) putchar(x)
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
using vi = V<int>;
using vb = V<bool>;
using vpi = V<pair<int,int>>;
using vvi = V<vi>;
using vl = V<ll>;
using vd = V<ld>;
using vstr = V<str>;
 
#define all(x) begin(x), end(x)
#define sor(x) sort(all(x))
#define rev(x) reverse(all(x))
#define sz(x) (int)(x).size()
#define rall(x) x.rbegin(), x.rend()
#define AR array
 
// loops
#define F0R(i, a, b) for (int i=a; i<b;++i)
#define FOR(i, a) for (int i=0; i<a;++i)
#define FORn(i, a) for (int i=1; i<=a;++i)
#define ROF(i,a) for(int i=a-1; i >= 0;--i)
#define R0F(i,a,b) for(int i=a; i > b;--i)
#define ROFn(i,a) for(int i=a; i > 0;--i)
#define rep(a) FOR(_, a)
#define trav(i,x) for(auto& i:x)
 
// pairs
#define mp make_pair
#define pi pair <int, int>
#define f first
#define s second
 
// vectors
#define lb lower_bound
#define ub upper_bound
#define SUM(v) accumulate(all(v), 0LL)
#define MN(v) *min_element(all(v))
#define MX(v) *max_element(all(v))
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define eb emplace_back
#define ft front()
#define bk back()
#define ins insert
#define pf push_front
#define pb push_back
#define emt empty()
#define rsz resize
 
#define pob pop_back()
#define pof pop_front()
 
#define ts to_string
 
#define setIO()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
ll MOD = 1e9+7;
const ll MAX = 100000000000;
const ll INF = 1e18; // not too close to LLONG_MAX
const ld PI = acos((ld)-1);
 
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
 
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
 
tcT> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }
 
//INPUT
#define tcTUU tcT, class ...U
tcT> void re(complex<T>& c);
tcTU> void re(pair<T,U>& p);
tcT> void re(V<T>& v);
tcT, size_t SZ> void re(AR<T,SZ>& a);
 
tcT> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }
 
tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; }
tcTU> void re(pair<T,U>& p) { re(p.f,p.s); }
tcT> void re(V<T>& x) { trav(a,x) re(a); }
tcT> void rv(int n, V<T>& x) { x.rsz(n); re(x); }
 
//OUTPUT
namespace output {
	tcT> void PS(V<T>& x) { FOR(i,sz(x)) cout << x[i] << " \n"[i + 1 == sz(x)];}
	tcT> void W(pair<T,T>& x) { cout << x.f << ' ' << x.s << '\n'; }
	tcT> void PS(bool ok) { if(ok) cout << "YES\n"; else cout << "NO\n"; }
    template<class T1, class T2> void pr(const pair<T1,T2>& x);
    tcT, size_t SZ> void pr(const array<T,SZ>& x);
    tcT> void pr(const vector<T>& x);
    tcT> void pr(const set<T>& x);
    template<class T1, class T2> void pr(const map<T1,T2>& x);
 
    tcT> void pr(const T& x) { cout << x; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        pr(first); pr(rest...);
    }
 
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{",x.f,", ",x.s,"}");
    }
    tcT> void prContain(const T& x) {
        pr("{");
        bool fst = 1; trav(a,x) pr(!fst?", ":"",a), fst = 0;
        pr("}");
    }
    tcT, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
    tcT> void pr(const vector<T>& x) { prContain(x); }
    tcT> void pr(const set<T>& x) { prContain(x); }
    template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }
 
    void ps() { pr("\n"); } // print w/ spaces
    template<class Arg> void ps(const Arg& first) { pr(first,"\n"); }
    template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
        pr(first," "); ps(rest...);
    }
}
 
using namespace output;
 
template<class T,class V> void add(T& a, const V& b) {
	a = (a + b) % MOD;
	}
template<class T,class V> void sub(T& a, const V& b) {
	a = (a - b + MOD) % MOD;
	}
template<class T,class V> void mult(T& a, const V& b) {
	a = a * b % MOD;
	}
 
void setF(string fileName = "") {
	ios_base::sync_with_stdio(0); cin.tie(0);
	if((int)fileName.size()) {
		freopen((fileName+".in").c_str(), "r", stdin);
		freopen((fileName+".out").c_str(), "w", stdout);
	}
}
 
 
vb bb;
vi SIEVE(int N){ // sieve in O(N logN)
	vi pr;
	bb.rsz(N);
	bb[0] = bb[1] = true;
	vi g(N);
	F0R(i,2,N){
		if(!bb[i]){
			pr.pb(i);
			for (int j = i + i; j < N; j += i) bb[j] = true;
			}
		}
	return pr;
	}
 
 
 
template<class T> using ordset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
struct edge{
	int a;
	int b;
	int w;
	};
 
ll POW(ll x, ll y,ll mod){
    ll res = 1LL;
    x %= mod;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}
 
ll fact(ll x) { if(x) return x * fact(x - 1ll); return 1; }
 
vl fc;
void F(int N,ll MOD){
	fc.rsz(N + 1);
	fc[0] = 1;
	FORn(i,N) fc[i] = fc[i - 1] * i * 1ll % MOD;
	}
 
vl inv;
void I(int N,ll MOD){
	inv.rsz(N + 1);
	inv[N] = POW(fc[N],MOD - 2,MOD);
	for (int i = N; i ;--i) inv[i - 1] = inv[i] * 1ll * i % MOD;
	}
 
ll Cr(ll N,ll K,ll mod){
	if(K < 0) return 0;
	if(K > N) return 0;
	return fc[N] * 1ll * inv[K] % mod * inv[N - K] % mod;
	}
ll Ar(ll N,ll K,ll mod){
	return fc[N] * inv[N - K] % mod;
	}
ll iv(int k,ll MOD){
  return POW(k,MOD-2,MOD);
}
 
/*
 scanf("%lld", &testInteger);
 printf("%lld", testInteger);
 
 ____ ____ ____ ____ ____  ____
||f |||l |||o |||p |||p ||||y ||
||__|||__|||__|||__|||__||||__||
|/__\|/__\|/__\|/__\|/__\||/__\|
 
**/
const ll inf = (ll)1e16;
int t;
bool ok;
template <class T> class SEG {
  private:
 
 
  public:
    int n;
	V<T>atleast,atmost,las1,las2,val;
	V<V<T>> lazy;
	vb ben;
	void init(int N){
		n = N;
		atleast = las1 = las2 = val = V<T>(6 * n);
		atmost = V<T>(6 * n,inf);
		ben = vb(6 * n);
		}
 
	void prop(int node,int son,int l,int r){
		//ps(las1[node],las2[node],l,r);
	    ben[son] = true;
	    if(atleast[son] < atleast[node]){
            atleast[son] = atleast[node];
            val[son] = val[node];
            las1[son] = las1[node];
	    }
        if(atmost[son] > atmost[node]){
            atmost[son] = atmost[node];
            las2[son] = las2[node];
        }
		if(atleast[son] >= atmost[son]){
			//ps(l,r,atleast[son],atmost[son]);
			if(las2[son] > las1[son]) {
				las1[son] = las2[son] - 1;
				atleast[son] = atmost[son];
				las1[son] = 0;
				val[son] = atmost[son];
				}
			else{
				las2[son] = las1[son] - 1;
				atmost[son] = inf;
				las2[son] = atleast[son];
				val[son] = atleast[son];
				}
			}
	}
 
	void propagate(int node,int l,int r){
        if(!ben[node]) return;
        ben[node] = false;
        prop(node,2 * node,l,r);
        prop(node,2 * node + 1,l,r);
        if(l != r){
			atleast[node] = 0;
			atmost[node] = inf;
			las1[node] = 0;
			las2[node] = 0;
			}
		//else ps(l,atleast[node],atmost[node]);
	}
 
	void change(int a,int b,int v,int l,int r,int x){
        T& y = atmost[x];
        T& z = atleast[x];
	    if(a <= l && r <= b){
			//ps(l,r,t);
            ben[x] = true;
            if(ok && z < v){
                las1[x] = t;
                val[x] = v;
                z = v;
                }
            else if(!ok && v < y){
                y = v;
                las2[x] = t;
               }
            if(atleast[x] > atmost[x]){
				//ps(l,r,atleast[x],atmost[x]);
				if(las2[x] > las1[x]) {
					atleast[x] = atmost[x];
					val[x] = atmost[x];
					las1[x] = 0;
					}
				else {
					atmost[x] = inf;
					las2[x] = atleast[x];
					val[x] = atleast[x];
					}
			}
            return;
        }
        propagate(x,l,r);
	    if(b < l || r < a) return;
		int mid = (l + r) / 2;
		int f1 = 2 * x;
		int f2 = f1 | 1;
		change(a,b,v,l,mid,f1);
		change(a,b,v,mid + 1,r,f2);
		}
 
	void change(int l,int r,int v){
		change(l,r,v,1,n,1);
		}
 
    int get(int node,int l,int r,int x){
        if(l == r) return x;
        int mid = (l + r) / 2;
        propagate(x,l,r);
        if(node <= mid) return get(node,l,mid,2 * x);
        return get(node,mid + 1,r,2 * x + 1);
    }
 
    int get(int node){
        return get(node,1,n,1);
    }
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    SEG<int> C;
    C.init(n);
   // int xx = C.get(4);
    FOR(i,k){
        left[i]++;
        right[i]++;
        ++t;
        ok = true;
        if(op[i] == 1) C.change(left[i],right[i],height[i]);
        else {
			ok = false;
			C.change(left[i],right[i],height[i]);
			}
    }
    FOR(i,n){
        int& a = finalHeight[i];
		//ps(C.atleast[xx],C.atmost[xx],C.las1[xx],C.las2[xx]);
        int x = C.get(i + 1);
        a = C.val[x];
        //ps(C.atleast[x],C.atmost[x],C.las1[x],C.las2[x]);
    }
    return;
}

Compilation message

wall.cpp: In instantiation of 'void SEG<T>::init(int) [with T = int]':
wall.cpp:366:13:   required from here
wall.cpp:262:23: warning: overflow in conversion from 'll' {aka 'long long int'} to 'std::vector<int>::value_type' {aka 'int'} changes value from '10000000000000000' to '1874919424' [-Woverflow]
  262 |   atmost = V<T>(6 * n,inf);
      |                       ^~~
wall.cpp: In instantiation of 'void SEG<T>::change(int, int, int, int, int, int) [with T = int]':
wall.cpp:349:9:   required from 'void SEG<T>::change(int, int, int) [with T = int]'
wall.cpp:373:59:   required from here
wall.cpp:332:18: warning: overflow in conversion from 'll' {aka 'long long int'} to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} changes value from '10000000000000000' to '1874919424' [-Woverflow]
  332 |      atmost[x] = inf;
      |                  ^~~
wall.cpp: In instantiation of 'void SEG<T>::propagate(int, int, int) [with T = int]':
wall.cpp:339:9:   required from 'void SEG<T>::change(int, int, int, int, int, int) [with T = int]'
wall.cpp:349:9:   required from 'void SEG<T>::change(int, int, int) [with T = int]'
wall.cpp:373:59:   required from here
wall.cpp:302:19: warning: overflow in conversion from 'll' {aka 'long long int'} to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} changes value from '10000000000000000' to '1874919424' [-Woverflow]
  302 |    atmost[node] = inf;
      |                   ^~~
wall.cpp: In instantiation of 'void SEG<T>::prop(int, int, int, int) [with T = int]':
wall.cpp:298:9:   required from 'void SEG<T>::propagate(int, int, int) [with T = int]'
wall.cpp:339:9:   required from 'void SEG<T>::change(int, int, int, int, int, int) [with T = int]'
wall.cpp:349:9:   required from 'void SEG<T>::change(int, int, int) [with T = int]'
wall.cpp:373:59:   required from here
wall.cpp:288:19: warning: overflow in conversion from 'll' {aka 'long long int'} to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} changes value from '10000000000000000' to '1874919424' [-Woverflow]
  288 |     atmost[son] = inf;
      |                   ^~~
wall.cpp: In function 'void setF(std::string)':
wall.cpp:165:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  165 |   freopen((fileName+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wall.cpp:166:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  166 |   freopen((fileName+".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Runtime error 3 ms 596 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 157 ms 8092 KB Output is correct
3 Incorrect 320 ms 5768 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Runtime error 3 ms 568 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Runtime error 3 ms 596 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -