Submission #891810

# Submission time Handle Problem Language Result Execution time Memory
891810 2023-12-24T05:23:53 Z Trisanu_Das Rectangles (IOI19_rect) C++17
Compilation error
0 ms 0 KB
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;

int n, m;
int bit[2505];
int a[2][2505][2505], lst[2][2505][2505], cnt[2][2505][2505];
vector<pair<int> > p[2]; 
vector<int> s[2][2505];

void upd(int idx, int val){
  for(idx++; idx < 2505; idx += (idx & -idx)) bit[idx] += val;
}

int qry(int idx){
  int ans = 0;
  for(idx++; idx; idx -= (idx & -idx)) ans += bit[idx];
  return ans;
}
 
long long count_rectangles(vector<vector<int>> A) {
	n = A.size(), m = A[0].size();
	for(int i = 0; i < n; i++) s[0][i].push_back(0);
	for(int i = 0; i < m; i++) s[1][i].push_back(0);
	long long ans = 0;
	for(int i = 0; i < n - 1; i++){
      for(int j = 0; j < m - 1; j++){
          a[0][i][j] = a[1][j][i] = A[i][j];
          a[0][i][j + 1] = A[i][j + 1];
          a[1][j][i + 1] = A[i + 1][j];
          for(int t = 0; t < 2; t++){
              bool eq = 0;
              p[t].clear();
              while(!s[t][i].empty()){
                  int c = s[t][i].back();
                  if(c < j && !eq){
                      if(lst[t][c][j + 1] != i - 1) cnt[t][c][j + 1] = 0;
                      cnt[t][c][j + 1]++, lst[t][c][j + 1] = i;
                      p[t].push_back({j - c, cnt[t][c][j + 1]});
                      if(t) swap(p[t].back().first, p[t].back().second);
                  }
                  eq = a[t][i][c] == a[t][i][j + 1];
                  if(a[t][i][c] <= a[t][i][j + 1]) s[t][i].pop_back();
                  else break;
              }
              s[t][i].push_back(j + 1);
              swap(i, j);
              sort(p[t].begin(), p[t].end(), greater<pair<int, int> >());
          }
          int it = 0;
          for(pair<int, int> v : p[0]){
              for(; it < p[1].size() && v.f <= p[1][it].first; it++) upd(p[1][it].second, 1);
              ans += qry(v.second);
          }
          for(int jt = 0; jt < it; jt++) upd(p[1][jt].second, -1);
      }
    }
	return ans;
}

Compilation message

rect.cpp:8:16: error: wrong number of template arguments (1, should be 2)
    8 | vector<pair<int> > p[2];
      |                ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/vector:60,
                 from rect.h:5,
                 from rect.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
  211 |     struct pair
      |            ^~~~
rect.cpp:8:18: error: template argument 1 is invalid
    8 | vector<pair<int> > p[2];
      |                  ^
rect.cpp:8:18: error: template argument 2 is invalid
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:33:20: error: request for member 'clear' in 'p[t]', which is of non-class type 'int'
   33 |               p[t].clear();
      |                    ^~~~~
rect.cpp:39:28: error: request for member 'push_back' in 'p[t]', which is of non-class type 'int'
   39 |                       p[t].push_back({j - c, cnt[t][c][j + 1]});
      |                            ^~~~~~~~~
rect.cpp:40:39: error: request for member 'back' in 'p[t]', which is of non-class type 'int'
   40 |                       if(t) swap(p[t].back().first, p[t].back().second);
      |                                       ^~~~
rect.cpp:40:58: error: request for member 'back' in 'p[t]', which is of non-class type 'int'
   40 |                       if(t) swap(p[t].back().first, p[t].back().second);
      |                                                          ^~~~
rect.cpp:48:25: error: request for member 'begin' in 'p[t]', which is of non-class type 'int'
   48 |               sort(p[t].begin(), p[t].end(), greater<pair<int, int> >());
      |                         ^~~~~
rect.cpp:48:39: error: request for member 'end' in 'p[t]', which is of non-class type 'int'
   48 |               sort(p[t].begin(), p[t].end(), greater<pair<int, int> >());
      |                                       ^~~
rect.cpp:51:37: error: 'begin' was not declared in this scope
   51 |           for(pair<int, int> v : p[0]){
      |                                     ^
rect.cpp:51:37: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from rect.cpp:2:
/usr/include/c++/10/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from rect.cpp:2:
/usr/include/c++/10/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
rect.cpp:51:37: error: 'end' was not declared in this scope
   51 |           for(pair<int, int> v : p[0]){
      |                                     ^
rect.cpp:51:37: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from rect.cpp:2:
/usr/include/c++/10/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from rect.cpp:2:
/usr/include/c++/10/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~
rect.cpp:52:31: error: request for member 'size' in 'p[1]', which is of non-class type 'int'
   52 |               for(; it < p[1].size() && v.f <= p[1][it].first; it++) upd(p[1][it].second, 1);
      |                               ^~~~
rect.cpp:52:43: error: 'struct std::pair<int, int>' has no member named 'f'
   52 |               for(; it < p[1].size() && v.f <= p[1][it].first; it++) upd(p[1][it].second, 1);
      |                                           ^
rect.cpp:52:52: error: invalid types 'int[int]' for array subscript
   52 |               for(; it < p[1].size() && v.f <= p[1][it].first; it++) upd(p[1][it].second, 1);
      |                                                    ^
rect.cpp:52:78: error: invalid types 'int[int]' for array subscript
   52 |               for(; it < p[1].size() && v.f <= p[1][it].first; it++) upd(p[1][it].second, 1);
      |                                                                              ^
rect.cpp:55:50: error: invalid types 'int[int]' for array subscript
   55 |           for(int jt = 0; jt < it; jt++) upd(p[1][jt].second, -1);
      |                                                  ^