Submission #918688

# Submission time Handle Problem Language Result Execution time Memory
918688 2024-01-30T08:51:04 Z xynex Rectangles (IOI19_rect) C++17
49 / 100
5000 ms 322916 KB
/**
  * Author: Tenjin
  * Created: 27.04.2022 18:58
  * Why am I so stupid? :c
  * Slishkom slab
**/

#include <bits/stdc++.h>

// #pragma GCC optimize("inline")
// #pragma GCC optimize("-fgcse,-fgcse-lm")
// #pragma GCC optimize("-ftree-pre,-ftree-vrp")
// #pragma GCC optimize("-ffast-math")
// #pragma GCC optimize("-fipa-sra")
// #pragma GCC optimize("-fpeephole2")
// #pragma GCC optimize("-fsched-spec")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define ll long long
#define pr pair
#define vt vector
#define ff first
#define ss second
#define sz(a) (int)a.size()
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<typename T> T get_rand(T l, T r) {
  random_device rd;
  mt19937 gen(rd());
  return uniform_int_distribution<T>(l, r)(gen);
}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(array<A, S>& a);
template<class T> void read(T& x) { cin >> x; }
void read(double& d) { string t; read(t); d = stod(t); }
void read(long double& d) { string t; read(t); d = stold(t); }
template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); }
template<class A> void read(vt<A>& x) { for (auto& a : x) read(a); }
template<class A, size_t S> void read(array<A, S>& x) { for (auto& a : x) read(a); }

string to_string(char c) { return string(1, c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return string(s); }
string to_string(string s) { return s; }
string to_string(vt<bool> v) { string res; for (int i = 0; i < sz(v); ++i) res += char('0' + v[i]); return res; }
template<size_t S> string to_string(bitset<S> b) { string res; for (int i = 0; i < S; ++i) res += char('0' + b[i]); return res; }
template<class T> string to_string(T v) { bool f = 1; string res; for (auto x : v) { if (!f) res += ' '; f = 0; res += to_string(x); } return res; }

template<class A> void write(A x) { cout << to_string(x); }
template<class H, class... T> void write(const H& h, const T&... t) { write(h); write(t...); }

void print() { write("\n"); }
template<class H, class... T> void print(const H& h, const T&... t) { write(h); if (sizeof...(t)) write(' '); print(t...); }

void freop(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}

const int MOD = 1e9 + 7;
const ll INF = 1e14;
const int M = 4e5 + 5;
const double long pi = acos(-1);
const double long eps = 1e-12;
const int sq = 700;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
/* ll vs int*/

const int N = 1e6 + 5;

map<pr<int, int>, bool> have;
bool valid[2501][2501];
ll count_rectangles(vt<vt<int>> a) {
  int n = sz(a);
  int m = sz(a[0]);
  vt<vt<int>> L(n, vt<int> (m, -1)), R(n, vt<int> (m, -1));
  vt<vt<int>> L1(n, vt<int> (m, -1)), R1(n, vt<int> (m, -1));
  for(int i = 0; i < n; ++i) {
    vt<pr<int, int> > st;
    for(int j = 0; j < m; ++j) {
      valid[i][j] = 1;
      while(!st.empty() && st.back().ff <= a[i][j]) st.pop_back();
      if(!st.empty()) L[i][j] = st.back().ss;
      else L[i][j] = -1;
      st.push_back({a[i][j], j});
    }
    st.clear();
    for(int j = m - 1; j >= 0; --j) {
      while(!st.empty() && st.back().ff <= a[i][j]) st.pop_back();
      if(!st.empty()) R[i][j] = st.back().ss;
      else R[i][j] = m;
      st.push_back({a[i][j], j});
    }
  }
  for(int i = 0; i < m; ++i) {
    vt<pr<int, int> > st;
    for(int j = 0; j < n; ++j) {
      while(!st.empty() && st.back().ff <= a[j][i]) st.pop_back();
      if(!st.empty()) L1[j][i] = st.back().ss;
      else L1[j][i] = -1;
      st.push_back({a[j][i], j});
    }
    st.clear();
    for(int j = n - 1; j >= 0; --j) {
      while(!st.empty() && st.back().ff <= a[j][i]) st.pop_back();
      if(!st.empty()) R1[j][i] = st.back().ss;
      else R1[j][i] = n;
      st.push_back({a[j][i], j});
    }
  }
  set<pr<int, int>> last;
  for(int i = 0; i < n; ++i) {
    set<pr<int, int>> nxt;
    for(int j = 0; j < m; ++j) {
      int limL = L1[i][j], limR = i;
     // print(i, j, limL, limR);
      if(limL == -1) {
        valid[i][j] = 0;
        continue;
      }
      int curL = L[i][j], curR = R[i][j];
     // print(curL, curR);
      if(curL == -1 || curR == m) {
        valid[i][j] = 0;
        continue;
      }
      curL *= n;
      curL += curR;
      auto fnd = last.lower_bound({curL, 0});
      int cur = 0;
      if(fnd != last.end() && (*fnd).ff == curL) {
        cur = (*fnd).ss;
      }
      cur++;
      //print(cur);
      if(cur < (limR - limL)) {
        valid[i][j] = 0;
      }
      //print(valid[i][j]);
      nxt.insert({curL, cur});
    }
    swap(last, nxt);
  }
  last.clear();
  for(int i = n - 1; i >= 0; --i) {
    set<pr<int, int>> nxt;
    for(int j = 0; j < m; ++j) {
      int limL = i, limR = R1[i][j];
      //print(i, j, limL, limR);
      if(limR == n) {
        valid[i][j] = 0;
        continue;
      }
      int curL = L[i][j], curR = R[i][j];
     // print(curL, curR);
      if(curL == -1 || curR == m) {
        valid[i][j] = 0;
        continue;
      }
      curL *= n;
      curL += curR;
      auto fnd = last.lower_bound({curL, 0});
      int cur = 0;
      if(fnd != last.end() && (*fnd).ff == curL) {
        cur = (*fnd).ss;
      }
      cur++;
      //print(cur);
      if(cur < (limR - limL)) {
        valid[i][j] = 0;
      }
      //print(valid[i][j]);
      nxt.insert({curL, cur});
    }
    swap(last, nxt);
  }
  last.clear();
  for(int i = 0; i < m; ++i) {
    set<pr<int, int>> nxt;
    for(int j = 0; j < n; ++j) {
      int limL = L[j][i], limR = i;
      //print(j, i, limL, limR);
      if(limL == -1) {
        valid[j][i] = 0;
        continue;
      }
      int curL = L1[j][i], curR = R1[j][i];
     // print(curL, curR);
      if(curL == -1 || curR == n) {
        valid[j][i] = 0;
        continue;
      }
      curL *= m;
      curL += curR;
      auto fnd = last.lower_bound({curL, 0});
      int cur = 0;
      if(fnd != last.end() && (*fnd).ff == curL) {
        cur = (*fnd).ss;
      }
      cur++;
      //print(cur);
      if(cur < (limR - limL)) {
        valid[j][i] = 0;
      }
      //print(valid[j][i]);
      nxt.insert({curL, cur});
    }
    swap(last, nxt);
  }
  last.clear();
  for(int i = m - 1; i >= 0; --i) {
    set<pr<int, int>> nxt;
    for(int j = 0; j < n; ++j) {
      int limL = i, limR = R[j][i];
      if(limR == m) {
        valid[j][i] = 0;
        continue;
      }
      int curL = L1[j][i], curR = R1[j][i];
      if(curL == -1 || curR == n) {
        valid[j][i] = 0;
        continue;
      }
      curL *= m;
      curL += curR;
      auto fnd = last.lower_bound({curL, 0});
      int cur = 0;
      if(fnd != last.end() && (*fnd).ff == curL) {
        cur = (*fnd).ss;
      }
      cur++;
      if(cur < (limR - limL)) {
        valid[j][i] = 0;
      }
      nxt.insert({curL, cur});
    }
    swap(last, nxt);
  }
  //vt<pr<int, int>> ord;
  int ans = 0;
  for(int i = 1; i < n; ++i) {
    for(int j = 1; j < m; ++j) {
      /*if(L[i][j] != L[i - 1][j] && R[i][j] != R[i - 1][j] && L1[i - 1][j] != L1[i][j] && R1[i][j] != R[i - 1][j] && L[i][j] != L[i][j - 1] && R[i][j] != R[i][j - 1] && L1[i][j - 1] != L1[i][j] && R1[i][j] != R[i][j - 1]) {
        ans += valid[i][j];
      }*/
      if(!have[{L[i][j] * n + R[i][j], L1[i][j] * m + R1[i][j]}]) ans += valid[i][j];
      have[{L[i][j] * n + R[i][j], L1[i][j] * m + R1[i][j]}] = 1;
    }
  }
  /*int ans = 0;
  for(auto cur : ord) ans += valid[cur.ff][cur.ss];*/
  return ans;
}

/*
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //freop("");
  int t = 1;
  //read(t);
  for (int i = 1; i <= t; ++i) {
    //write("Case #" + to_string(i) + ": ");
    solve();
  }
  return 0;
}*/

Compilation message

rect.cpp: In function 'void freop(std::string)':
rect.cpp:64:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |   freopen((s + ".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rect.cpp:65:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |   freopen((s + ".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 4 ms 3160 KB Output is correct
23 Correct 4 ms 3164 KB Output is correct
24 Correct 4 ms 3164 KB Output is correct
25 Correct 4 ms 2908 KB Output is correct
26 Correct 5 ms 3160 KB Output is correct
27 Correct 5 ms 3204 KB Output is correct
28 Correct 5 ms 3164 KB Output is correct
29 Correct 3 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 4 ms 3160 KB Output is correct
18 Correct 4 ms 3164 KB Output is correct
19 Correct 4 ms 3164 KB Output is correct
20 Correct 4 ms 2908 KB Output is correct
21 Correct 5 ms 3160 KB Output is correct
22 Correct 5 ms 3204 KB Output is correct
23 Correct 5 ms 3164 KB Output is correct
24 Correct 3 ms 2908 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 21 ms 6224 KB Output is correct
31 Correct 21 ms 6232 KB Output is correct
32 Correct 24 ms 6376 KB Output is correct
33 Correct 21 ms 4952 KB Output is correct
34 Correct 33 ms 6020 KB Output is correct
35 Correct 34 ms 6224 KB Output is correct
36 Correct 36 ms 5744 KB Output is correct
37 Correct 31 ms 5964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 4 ms 3160 KB Output is correct
18 Correct 4 ms 3164 KB Output is correct
19 Correct 4 ms 3164 KB Output is correct
20 Correct 4 ms 2908 KB Output is correct
21 Correct 5 ms 3160 KB Output is correct
22 Correct 5 ms 3204 KB Output is correct
23 Correct 5 ms 3164 KB Output is correct
24 Correct 3 ms 2908 KB Output is correct
25 Correct 21 ms 6224 KB Output is correct
26 Correct 21 ms 6232 KB Output is correct
27 Correct 24 ms 6376 KB Output is correct
28 Correct 21 ms 4952 KB Output is correct
29 Correct 33 ms 6020 KB Output is correct
30 Correct 34 ms 6224 KB Output is correct
31 Correct 36 ms 5744 KB Output is correct
32 Correct 31 ms 5964 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 237 ms 47828 KB Output is correct
39 Correct 190 ms 47992 KB Output is correct
40 Correct 254 ms 47952 KB Output is correct
41 Correct 259 ms 47952 KB Output is correct
42 Correct 344 ms 48048 KB Output is correct
43 Correct 344 ms 47956 KB Output is correct
44 Correct 369 ms 48372 KB Output is correct
45 Correct 326 ms 45392 KB Output is correct
46 Correct 266 ms 27716 KB Output is correct
47 Correct 312 ms 32668 KB Output is correct
48 Correct 627 ms 46544 KB Output is correct
49 Correct 577 ms 48720 KB Output is correct
50 Correct 247 ms 25428 KB Output is correct
51 Correct 264 ms 25436 KB Output is correct
52 Correct 496 ms 41704 KB Output is correct
53 Correct 504 ms 42836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 856 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Incorrect 3 ms 860 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1933 ms 150072 KB Output is correct
8 Correct 4972 ms 322916 KB Output is correct
9 Execution timed out 5040 ms 315884 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 4 ms 3160 KB Output is correct
18 Correct 4 ms 3164 KB Output is correct
19 Correct 4 ms 3164 KB Output is correct
20 Correct 4 ms 2908 KB Output is correct
21 Correct 5 ms 3160 KB Output is correct
22 Correct 5 ms 3204 KB Output is correct
23 Correct 5 ms 3164 KB Output is correct
24 Correct 3 ms 2908 KB Output is correct
25 Correct 21 ms 6224 KB Output is correct
26 Correct 21 ms 6232 KB Output is correct
27 Correct 24 ms 6376 KB Output is correct
28 Correct 21 ms 4952 KB Output is correct
29 Correct 33 ms 6020 KB Output is correct
30 Correct 34 ms 6224 KB Output is correct
31 Correct 36 ms 5744 KB Output is correct
32 Correct 31 ms 5964 KB Output is correct
33 Correct 237 ms 47828 KB Output is correct
34 Correct 190 ms 47992 KB Output is correct
35 Correct 254 ms 47952 KB Output is correct
36 Correct 259 ms 47952 KB Output is correct
37 Correct 344 ms 48048 KB Output is correct
38 Correct 344 ms 47956 KB Output is correct
39 Correct 369 ms 48372 KB Output is correct
40 Correct 326 ms 45392 KB Output is correct
41 Correct 266 ms 27716 KB Output is correct
42 Correct 312 ms 32668 KB Output is correct
43 Correct 627 ms 46544 KB Output is correct
44 Correct 577 ms 48720 KB Output is correct
45 Correct 247 ms 25428 KB Output is correct
46 Correct 264 ms 25436 KB Output is correct
47 Correct 496 ms 41704 KB Output is correct
48 Correct 504 ms 42836 KB Output is correct
49 Correct 3 ms 856 KB Output is correct
50 Correct 2 ms 860 KB Output is correct
51 Correct 1 ms 600 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Incorrect 3 ms 860 KB Output isn't correct
54 Halted 0 ms 0 KB -