Submission #388337

#TimeUsernameProblemLanguageResultExecution timeMemory
388337clifter조화행렬 (KOI18_matrix)C++14
Compilation error
0 ms0 KiB
, point b) {return a.x<b.x;} bool cmpy(point a, point b) {return a.y<b.y;} int map[4][305000]; int arr[305000], ans[300500], ytoz[300500]; vector<int> elem[805000], maxtree[806000]; point p[300500]; void init(int s, int e, int node){ if(s==e) elem[node].push_back(ytoz[s]); else{ int mid = (s+e)/2; init(s, mid, node*2); init(mid+1, e, node*2+1); int pt1 = 0, pt2 = 0; while(pt1<elem[node*2].size()&&pt2<elem[node*2+1].size()){ if(elem[node*2][pt1]<elem[node*2+1][pt2]) elem[node].push_back(elem[node*2][pt1++]); else if(elem[node*2][pt1]>elem[node*2+1][pt2]) elem[node].push_back(elem[node*2+1][pt2++]); else{ elem[node].push_back(elem[node*2][pt1++]); pt2++; } } for(int i=pt1; i<elem[node*2].size(); i++) elem[node].push_back(elem[node*2][i]); for(int i=pt2; i<elem[node*2+1].size(); i++) elem[node].push_back(elem[node*2+1][i]); } } void insert_node(int pos, int val, int s, int e, int node, int nodez){ if(pos<s||pos>e) return; maxtree[node][nodez] = maxtree[node][nodez]<val?val:maxtree[node][nodez]; if(s!=e){ insert_node(pos, val, s, (s+e)/2, node, nodez*2); insert_node(pos, val, (s+e)/2+1, e, node, nodez*2+1); } } void insert(int y, int z, int val, int s, int e, int node, int m){ if(y<s||y>e) return; int coord = lower_bound(elem[node].begin(), elem[node].end(), z)-elem[node].begin()+1; insert_node(coord, val, 1, elem[node].size(), node, 1); if(s!=e){ insert(y,z,val,s,(s+e)/2,node*2,m); insert(y,z,val,(s+e)/2+1,e,node*2+1,m); } } int getmax_node(int z1, int z2, int s, int e, int node, int nodez){ if(e<z1||s>z2) return -1; else if(z1<=s&&e<=z2) return maxtree[node][nodez]; else{ int a = getmax_node(z1, z2, s, (s+e)/2, node, nodez*2); int b = getmax_node(z1, z2, (s+e)/2+1, e, node, nodez*2+1); return a<b?b:a; } } int getmax(int y1, int y2, int z1, int z2, int s, int e, int node, int m){ int c1 = lower_bound(elem[node].begin(), elem[node].end(), z1)-elem[node].begin()+1; int c2 = lower_bound(elem[node].begin(), elem[node].end(), z2)-elem[node].begin()+1; if(e<y1||s>y2) return -1; else if(y1<=s&&e<=y2) return getmax_node(c1, c2, 1, elem[node].size(), node, 1); else{ int a = getmax(y1, y2, z1, z2, s, (s+e)/2, node*2, m); int b = getmax(y1, y2, z1, z2, (s+e)/2+1, e, node*2+1, m); return a>b?a:b; } } int main() { int n,m; cin.sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin>>n>>m; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ cin>>arr[j]; //arr[j] = j; map[i][j] = arr[j]; } sort(arr+1, arr+m+1); for(int j=1; j<=m; j++){ map[i][j] = lower_bound(arr+1, arr+m+1, map[i][j])-arr; } } for(int j=1; j<=m; j++) { p[j].x = map[1][j]; p[j].y = map[2][j]; p[j].z = (n==2)?1:map[3][j]; ytoz[p[j].y] = p[j].z; } sort(p+1, p+m+1, cmpx); init(1, m, 1); for(int i=1; i<=4*m; i++){ if(elem[i].size()!=0) maxtree[i].resize(4*elem[i].size()+1); } int ans = -123; for(int i=1; i<=m; i++){ int t = getmax(1, p[i].y, 1, p[i].z, 1, m, 1, m)+1; if(ans<t) ans = t; //cout<<t<<" "; insert(p[i].y, p[i].z, t, 1, m, 1, m); } cout<<ans; }

Compilation message (stderr)

matrix.cpp:1:1: error: expected unqualified-id before ',' token
    1 | , point b) {return a.x<b.x;}
      | ^
matrix.cpp:1:9: error: expected constructor, destructor, or type conversion before 'b'
    1 | , point b) {return a.x<b.x;}
      |         ^
matrix.cpp:2:11: error: 'point' was not declared in this scope; did you mean 'int'?
    2 | bool cmpy(point a, point b) {return a.y<b.y;}
      |           ^~~~~
      |           int
matrix.cpp:2:20: error: 'point' was not declared in this scope; did you mean 'int'?
    2 | bool cmpy(point a, point b) {return a.y<b.y;}
      |                    ^~~~~
      |                    int
matrix.cpp:2:27: error: expression list treated as compound expression in initializer [-fpermissive]
    2 | bool cmpy(point a, point b) {return a.y<b.y;}
      |                           ^
matrix.cpp:5:1: error: 'vector' does not name a type
    5 | vector<int> elem[805000], maxtree[806000];
      | ^~~~~~
matrix.cpp:6:1: error: 'point' does not name a type; did you mean 'int'?
    6 | point p[300500];
      | ^~~~~
      | int
matrix.cpp: In function 'void init(int, int, int)':
matrix.cpp:9:12: error: 'elem' was not declared in this scope
    9 |   if(s==e) elem[node].push_back(ytoz[s]);
      |            ^~~~
matrix.cpp:18:15: error: 'elem' was not declared in this scope
   18 |     while(pt1<elem[node*2].size()&&pt2<elem[node*2+1].size()){
      |               ^~~~
matrix.cpp:31:22: error: 'elem' was not declared in this scope
   31 |     for(int i=pt1; i<elem[node*2].size(); i++) elem[node].push_back(elem[node*2][i]);
      |                      ^~~~
matrix.cpp:32:22: error: 'elem' was not declared in this scope
   32 |     for(int i=pt2; i<elem[node*2+1].size(); i++) elem[node].push_back(elem[node*2+1][i]);
      |                      ^~~~
matrix.cpp: In function 'void insert_node(int, int, int, int, int, int)':
matrix.cpp:41:3: error: 'maxtree' was not declared in this scope
   41 |   maxtree[node][nodez] = maxtree[node][nodez]<val?val:maxtree[node][nodez];
      |   ^~~~~~~
matrix.cpp: In function 'void insert(int, int, int, int, int, int, int)':
matrix.cpp:52:27: error: 'elem' was not declared in this scope
   52 |   int coord = lower_bound(elem[node].begin(), elem[node].end(), z)-elem[node].begin()+1;
      |                           ^~~~
matrix.cpp:52:15: error: 'lower_bound' was not declared in this scope
   52 |   int coord = lower_bound(elem[node].begin(), elem[node].end(), z)-elem[node].begin()+1;
      |               ^~~~~~~~~~~
matrix.cpp: In function 'int getmax_node(int, int, int, int, int, int)':
matrix.cpp:64:32: error: 'maxtree' was not declared in this scope
   64 |   else if(z1<=s&&e<=z2) return maxtree[node][nodez];
      |                                ^~~~~~~
matrix.cpp: In function 'int getmax(int, int, int, int, int, int, int, int)':
matrix.cpp:77:24: error: 'elem' was not declared in this scope
   77 |   int c1 = lower_bound(elem[node].begin(), elem[node].end(), z1)-elem[node].begin()+1;
      |                        ^~~~
matrix.cpp:77:12: error: 'lower_bound' was not declared in this scope
   77 |   int c1 = lower_bound(elem[node].begin(), elem[node].end(), z1)-elem[node].begin()+1;
      |            ^~~~~~~~~~~
matrix.cpp: In function 'int main()':
matrix.cpp:95:3: error: 'cin' was not declared in this scope
   95 |   cin.sync_with_stdio(false);
      |   ^~~
matrix.cpp:97:3: error: 'cout' was not declared in this scope
   97 |   cout.tie(nullptr);
      |   ^~~~
matrix.cpp:109:5: error: 'sort' was not declared in this scope; did you mean 'short'?
  109 |     sort(arr+1, arr+m+1);
      |     ^~~~
      |     short
matrix.cpp:113:19: error: 'lower_bound' was not declared in this scope
  113 |       map[i][j] = lower_bound(arr+1, arr+m+1, map[i][j])-arr;
      |                   ^~~~~~~~~~~
matrix.cpp:120:5: error: 'p' was not declared in this scope
  120 |     p[j].x = map[1][j]; p[j].y = map[2][j]; p[j].z = (n==2)?1:map[3][j];
      |     ^
matrix.cpp:125:8: error: 'p' was not declared in this scope
  125 |   sort(p+1, p+m+1, cmpx);
      |        ^
matrix.cpp:125:20: error: 'cmpx' was not declared in this scope; did you mean 'cmpy'?
  125 |   sort(p+1, p+m+1, cmpx);
      |                    ^~~~
      |                    cmpy
matrix.cpp:125:3: error: 'sort' was not declared in this scope; did you mean 'short'?
  125 |   sort(p+1, p+m+1, cmpx);
      |   ^~~~
      |   short
matrix.cpp:131:8: error: 'elem' was not declared in this scope
  131 |     if(elem[i].size()!=0) maxtree[i].resize(4*elem[i].size()+1);
      |        ^~~~
matrix.cpp:131:27: error: 'maxtree' was not declared in this scope
  131 |     if(elem[i].size()!=0) maxtree[i].resize(4*elem[i].size()+1);
      |                           ^~~~~~~