답안 #180365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
180365 2020-01-09T01:39:07 Z FieryPhoenix 벽 (IOI14_wall) C++11
100 / 100
2996 ms 125436 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
#include <deque>
#include <cassert>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <chrono>
#include <ctime>
#include <random>
#include <stack>
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
#define INF 2001001001
#define MOD 1000000007

struct LazySegmentTree{
  int siz;
  vector<ll>tree,lazyAdd,lazySub;
  LazySegmentTree(int temp){
    siz=temp;
    while ((siz&(siz-1))!=0) siz++;
    for (int i=0;i<siz*2;i++){
      tree.push_back(0);
      lazyAdd.push_back(-INF);
      lazySub.push_back(INF);
    }
  }
  void calc(int node){
    tree[node]=max(tree[node],lazyAdd[node]);
    tree[node]=min(tree[node],lazySub[node]);
  }
  void propagate(int node, int L, int R){
    calc(node);
    if (L!=R){
      calc(node*2);
      calc(node*2+1);
      applySub(node*2,lazySub[node]);
      applyAdd(node*2,lazyAdd[node]);
      applySub(node*2+1,lazySub[node]);
      applyAdd(node*2+1,lazyAdd[node]);
      calc(node*2);
      calc(node*2+1);
    }
    lazyAdd[node]=-INF;
    lazySub[node]=INF;
  }
  void applyAdd(int node, ll x){
    if (x>lazyAdd[node]){
      lazyAdd[node]=x;
      lazySub[node]=max(lazySub[node],x);
    }
  }
   void applySub(int node, ll x){
    if (x<lazySub[node]){
      lazySub[node]=x;
      lazyAdd[node]=min(lazyAdd[node],x);
    }
  }
  void update(int node, int L, int R, int i, int j, ll x, int type){
    propagate(node,L,R);
    if (L>R || L>j || R<i)
      return;
    if (L>=i && R<=j){
      if (type==1)
	applyAdd(node,x);
      else
	applySub(node,x);
      propagate(node,L,R);
      return;
    }
    update(node*2,L,(L+R)/2,i,j,x,type);
    update(node*2+1,(L+R)/2+1,R,i,j,x,type);
    //tree[node]=tree[node*2]+tree[node*2+1];
  }
  ll query(int node, int L, int R, int i,int j){
    if (L>R || L>j || R<i)
      return 0;
    propagate(node,L,R);
    //cout<<"QPOP "<<node<<endl;
    if (L>=i && R<=j){
      //cout<<"FOUND "<<node<<endl;
      return tree[node];
    }
    ll q1=query(node*2,L,(L+R)/2,i,j);
    ll q2=query(node*2+1,(L+R)/2+1,R,i,j);
    return q1+q2;
  }
  ll query(int i, int j){ return query(1,0,siz-1,i,j); }
  void update(int i, int j, ll val, int type){ update(1,0,siz-1,i,j,val,type); }
};

void buildWall(int N, int K, int op[], int l[], int r[], int h[], int finalh[]){
  LazySegmentTree lst=LazySegmentTree(N);
  for (int i=0;i<K;i++){
    lst.update(l[i],r[i],h[i],op[i]);
    /*
    bool debug=false;
    if (debug){
      cout<<"BEFORE: "<<endl;
      for (int j=1;j<lst.siz*2;j++)
	cout<<j<<": "<<lst.lazyAdd[j]<<' '<<lst.lazySub[j]<<endl;
    }
    for (int j=0;j<N;j++)
      cout<<lst.query(j,j)<<' ';
    cout<<endl;
    if (debug){
      cout<<"AFTER: "<<endl;
      for (int j=1;j<lst.siz*2;j++)
	cout<<j<<": "<<lst.lazyAdd[j]<<' '<<lst.lazySub[j]<<endl;
    }
    */
  }
  for (int i=0;i<N;i++)
    finalh[i]=lst.query(i,i);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 22 ms 1392 KB Output is correct
5 Correct 16 ms 1392 KB Output is correct
6 Correct 17 ms 1392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 175 ms 13916 KB Output is correct
3 Correct 514 ms 9284 KB Output is correct
4 Correct 1657 ms 24544 KB Output is correct
5 Correct 702 ms 25196 KB Output is correct
6 Correct 691 ms 23656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 22 ms 1392 KB Output is correct
5 Correct 16 ms 1520 KB Output is correct
6 Correct 16 ms 1392 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 179 ms 13944 KB Output is correct
9 Correct 579 ms 9416 KB Output is correct
10 Correct 1641 ms 24528 KB Output is correct
11 Correct 736 ms 25168 KB Output is correct
12 Correct 692 ms 23504 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 173 ms 14048 KB Output is correct
15 Correct 106 ms 3260 KB Output is correct
16 Correct 1898 ms 24532 KB Output is correct
17 Correct 712 ms 23948 KB Output is correct
18 Correct 715 ms 24144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 22 ms 1392 KB Output is correct
5 Correct 17 ms 1392 KB Output is correct
6 Correct 17 ms 1520 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 172 ms 13976 KB Output is correct
9 Correct 520 ms 9328 KB Output is correct
10 Correct 1745 ms 24652 KB Output is correct
11 Correct 705 ms 25160 KB Output is correct
12 Correct 688 ms 23584 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 176 ms 14044 KB Output is correct
15 Correct 103 ms 3428 KB Output is correct
16 Correct 2106 ms 24524 KB Output is correct
17 Correct 695 ms 24060 KB Output is correct
18 Correct 706 ms 24084 KB Output is correct
19 Correct 2966 ms 125276 KB Output is correct
20 Correct 2953 ms 125256 KB Output is correct
21 Correct 2995 ms 125272 KB Output is correct
22 Correct 2949 ms 125116 KB Output is correct
23 Correct 2986 ms 125348 KB Output is correct
24 Correct 2983 ms 125436 KB Output is correct
25 Correct 2960 ms 125224 KB Output is correct
26 Correct 2982 ms 125300 KB Output is correct
27 Correct 2996 ms 125216 KB Output is correct
28 Correct 2962 ms 125140 KB Output is correct
29 Correct 2980 ms 125136 KB Output is correct
30 Correct 2976 ms 125308 KB Output is correct