Submission #753693

# Submission time Handle Problem Language Result Execution time Memory
753693 2023-06-05T17:23:47 Z Sam_a17 Wall (IOI14_wall) C++17
100 / 100
1256 ms 78892 KB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include "temp.cpp"
#include <cstdio>
using namespace std;
 
#ifndef ONLINE_JUDGE
#define dbg(x) cerr << #x <<" "; print(x); cerr << endl;
#else
#define dbg(x)
#endif
 
#define sz(x) (int((x).size()))
#define len(x) (int)x.length()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define clr(x) (x).clear()
#define uniq(x) x.resize(unique(all(x)) - x.begin());
 
#define pb push_back
#define popf pop_front
#define popb pop_back
#define ld long double
#define ll long long
 
void print(long long t) {cerr << t;}
void print(int t) {cerr << t;}
void print(string t) {cerr << t;}
void print(char t) {cerr << t;}
void print(double t) {cerr << t;}
void print(unsigned long long t) {cerr << t;}
void print(long double t) {cerr << t;}
 
template <class T, class V> void print(pair <T, V> p);
template <class T> void print(vector <T> v);
template <class T> void print(set <T> v);
template <class T, class V> void print(map <T, V> v);
template <class T> void print(multiset <T> v);
template <class T> void print(T v[],T n) {cerr << "["; for(int i = 0; i < n; i++) {cerr << v[i] << " ";} cerr << "]";}
template <class T, class V> void print(pair <T, V> p) {cerr << "{"; print(p.first); cerr << ","; print(p.second); cerr << "}";}
template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(deque <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]";}
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define nl '\n'
 
// for random generations
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 myrand(131);
 
// for grid problems
int dx[8] = {-1,0,1,0,1,-1,1,-1};
int dy[8] = {0,1,0,-1,1,1,-1,-1};
 
long long ka() {
	long long x = 0;
	bool z = false;
	while (1)
	{
		char y = getchar();
		if (y == '-')
			z = true;
		else if ('0' <= y && y <= '9')
			x = x * 10 + y - '0';
		else
		{
			if (z)
				x *= -1;
			return x;
		}
	}
}
 
// lowest / (1 << 17) >= 1e5 / (1 << 18) >= 2e5 / (1 << 21) >= 1e6
void fastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
}
// file in/out
void setIO(string str = "") {
  fastIO();
 
  if (str != "") {
    freopen((str + ".in").c_str(), "r", stdin);
    freopen((str + ".out").c_str(), "w", stdout);
  }
}
 
// Indexed Set
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e5 + 10;
vector<int> a[N], ad[N], b[N], bd[N];

struct segTree {
  struct node {
    int mn, mx;
  };
  vector<node> tree;
  int size = 1;

  void init(int s) {
    while (size < s) {
      size *= 2;
    }
    tree.assign(2 * size - 1, {0, 0});
  }

  node combine(node a, node b) {
    a.mn = min(a.mn, b.mn);
    a.mx = max(a.mx, b.mx);
    return a;
  }

  void prop(int x, int lx, int rx) {
    if(rx - lx == 1) {
      return;
    }

    //
    tree[2 * x + 1].mn = max(tree[2 * x + 1].mn, tree[x].mn);
    tree[2 * x + 1].mx = max(tree[2 * x + 1].mx, tree[x].mn);

    tree[2 * x + 1].mn = min(tree[2 * x + 1].mn, tree[x].mx);
    tree[2 * x + 1].mx = min(tree[2 * x + 1].mx, tree[x].mx);

    //
    tree[2 * x + 2].mn = max(tree[2 * x + 2].mn, tree[x].mn);
    tree[2 * x + 2].mx = max(tree[2 * x + 2].mx, tree[x].mn);

    tree[2 * x + 2].mn = min(tree[2 * x + 2].mn, tree[x].mx);
    tree[2 * x + 2].mx = min(tree[2 * x + 2].mx, tree[x].mx);
  }

  void upd(int l, int r, int op, int value, int x, int lx, int rx) {
    prop(x, lx, rx);
    if(lx >= r || rx <= l) {
      return;
    }

    if(lx >= l && rx <= r) {
      if(op == 1) {
        tree[x].mn = max(tree[x].mn, value);
        tree[x].mx = max(tree[x].mx, value);
      } else {
        tree[x].mn = min(tree[x].mn, value);
        tree[x].mx = min(tree[x].mx, value);
      }
      prop(x, lx, rx);
      return;
    }

    int mid = (lx + rx) / 2;
    upd(l, r, op, value, 2 * x + 1, lx, mid);
    upd(l, r, op, value, 2 * x + 2, mid, rx);
    tree[x] = combine(tree[2 * x + 1], tree[2 * x + 2]);
  }

  void upd(int l, int r, int op, int value) {
    upd(l, r, op, value, 0, 0, size);
  }

  int get(int u, int x, int lx, int rx) {
    prop(x, lx, rx);
    if(rx - lx == 1) {
      assert(tree[x].mn == tree[x].mx);
      return tree[x].mn;
    }

    int mid = (lx + rx) / 2;
    if(u < mid) {
      return get(u, 2 * x + 1, lx, mid);
    } else {
      return get(u, 2 * x + 2, mid, rx);
    }
  }

  int get(int u) {
    return get(u, 0, 0, size);
  } 
};
segTree seg;


void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
  seg.init(n + 1);
  for(int i = 0; i < k; i++) {
    seg.upd(left[i], right[i] + 1, op[i], height[i]);
  }

  for(int i = 0; i < n; i++) {
    finalHeight[i] = seg.get(i);
  }
}

Compilation message

wall.cpp: In function 'void setIO(std::string)':
wall.cpp:88:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |     freopen((str + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wall.cpp:89:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |     freopen((str + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 9 ms 9812 KB Output is correct
3 Correct 7 ms 9684 KB Output is correct
4 Correct 17 ms 10176 KB Output is correct
5 Correct 19 ms 10160 KB Output is correct
6 Correct 15 ms 10188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9704 KB Output is correct
2 Correct 186 ms 23340 KB Output is correct
3 Correct 254 ms 17272 KB Output is correct
4 Correct 688 ms 29700 KB Output is correct
5 Correct 439 ms 30880 KB Output is correct
6 Correct 423 ms 29200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 10 ms 9784 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 18 ms 10172 KB Output is correct
5 Correct 13 ms 10156 KB Output is correct
6 Correct 13 ms 10176 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 151 ms 23264 KB Output is correct
9 Correct 244 ms 17300 KB Output is correct
10 Correct 667 ms 29700 KB Output is correct
11 Correct 422 ms 30712 KB Output is correct
12 Correct 413 ms 29260 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 150 ms 23240 KB Output is correct
15 Correct 43 ms 11368 KB Output is correct
16 Correct 647 ms 29996 KB Output is correct
17 Correct 398 ms 29384 KB Output is correct
18 Correct 418 ms 29452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 8 ms 9840 KB Output is correct
3 Correct 7 ms 9732 KB Output is correct
4 Correct 14 ms 10196 KB Output is correct
5 Correct 14 ms 10228 KB Output is correct
6 Correct 13 ms 10196 KB Output is correct
7 Correct 5 ms 9704 KB Output is correct
8 Correct 151 ms 23344 KB Output is correct
9 Correct 228 ms 17324 KB Output is correct
10 Correct 668 ms 29704 KB Output is correct
11 Correct 408 ms 30888 KB Output is correct
12 Correct 407 ms 29228 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 152 ms 23280 KB Output is correct
15 Correct 42 ms 11296 KB Output is correct
16 Correct 635 ms 29920 KB Output is correct
17 Correct 425 ms 29420 KB Output is correct
18 Correct 426 ms 29384 KB Output is correct
19 Correct 1253 ms 78892 KB Output is correct
20 Correct 1202 ms 76420 KB Output is correct
21 Correct 1238 ms 78820 KB Output is correct
22 Correct 1256 ms 76428 KB Output is correct
23 Correct 1219 ms 76620 KB Output is correct
24 Correct 1252 ms 76444 KB Output is correct
25 Correct 1231 ms 76408 KB Output is correct
26 Correct 1239 ms 78856 KB Output is correct
27 Correct 1235 ms 78844 KB Output is correct
28 Correct 1221 ms 76692 KB Output is correct
29 Correct 1221 ms 76448 KB Output is correct
30 Correct 1240 ms 76476 KB Output is correct