Submission #127157

#TimeUsernameProblemLanguageResultExecution timeMemory
127157arnold518조화행렬 (KOI18_matrix)C++14
23 / 100
4089 ms786436 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2e5; int M, N, ans; struct Data { int a, b, c; bool operator < (const Data& p) { return a<p.a; } }; Data A[MAXN+10]; struct Node1 { Node1() : val(0), lc(NULL), rc(NULL) {} int val; Node1 *lc, *rc; }; struct Node2 { Node2() : val(0), lc(NULL), rc(NULL) {} Node1 *val; Node2 *lc, *rc; }; Node2 *root=new Node2; void update1(Node1 *node, int tl, int tr, int pos, int val) { if(tl==tr) { node->val=val; return; } int mid=tl+tr>>1; if(pos<=mid) { if(node->lc==NULL) node->lc=new Node1; update1(node->lc, tl, mid, pos, val); } else { if(node->rc==NULL) node->rc=new Node1; update1(node->rc, mid+1, tr, pos, val); } node->val=0; if(node->lc!=NULL) node->val=max(node->val, node->lc->val); if(node->rc!=NULL) node->val=max(node->val, node->rc->val); } int query1(Node1 *node, int tl, int tr, int l, int r) { if(l<=tl && tr<=r) return node->val; if(r<tl || tr<l) return 0; int mid=tl+tr>>1; int ret=0; if(node->lc!=NULL) ret=max(ret, query1(node->lc, tl, mid, l, r)); if(node->rc!=NULL) ret=max(ret, query1(node->rc, mid+1, tr, l, r)); return ret; } void update2(Node2 *node, int tl, int tr, int ypos, int xpos, int val) { if(node->val==NULL) node->val=new Node1; if(tl==tr) { update1(node->val, 1, N, xpos, val); return; } int mid=tl+tr>>1; if(ypos<=mid) { if(node->lc==NULL) node->lc=new Node2; update2(node->lc, tl, mid, ypos, xpos, val); } else { if(node->rc==NULL) node->rc=new Node2; update2(node->rc, mid+1, tr, ypos, xpos, val); } int t=0; if(node->lc!=NULL) t=max(t, query1(node->lc->val, 1, N, xpos, xpos)); if(node->rc!=NULL) t=max(t, query1(node->rc->val, 1, N, xpos, xpos)); update1(node->val, 1, N, xpos, t); } int query2(Node2 *node, int tl, int tr, int yl, int yr, int xl, int xr) { if(yl<=tl && tr<=yr) { if(node->val!=NULL) return query1(node->val, 1, N, xl, xr); else return 0; } if(tr<yl || yr<tl) return 0; int mid=tl+tr>>1; int ret=0; if(node->lc!=NULL) ret=max(ret, query2(node->lc, tl, mid, yl, yr, xl, xr)); if(node->rc!=NULL) ret=max(ret, query2(node->rc, mid+1, tr, yl, yr, xl, xr)); return ret; } int main() { int i, j; scanf("%d%d", &M, &N); vector<int> Vb, Vc; for(i=1; i<=N; i++) scanf("%d", &A[i].a); for(i=1; i<=N; i++) scanf("%d", &A[i].b), Vb.push_back(A[i].b); if(M==3) for(i=1; i<=N; i++) scanf("%d", &A[i].c), Vc.push_back(A[i].c); sort(A+1, A+N+1); if(M==2) for(i=1; i<=N; i++) A[i].c=i, Vc.push_back(A[i].c); sort(Vb.begin(), Vb.end()); sort(Vc.begin(), Vc.end()); for(i=1; i<=N; i++) A[i].b=lower_bound(Vb.begin(), Vb.end(), A[i].b)-Vb.begin()+1; for(i=1; i<=N; i++) A[i].c=lower_bound(Vc.begin(), Vc.end(), A[i].c)-Vc.begin()+1; for(i=1; i<=N; i++) { int now=query2(root, 1, N, 1, A[i].b, 1, A[i].c)+1; ans=max(ans, now); update2(root, 1, N, A[i].b, A[i].c, now); } printf("%d", ans); }

Compilation message (stderr)

matrix.cpp: In function 'void update1(Node1*, int, int, int, int)':
matrix.cpp:40:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=tl+tr>>1;
             ~~^~~
matrix.cpp: In function 'int query1(Node1*, int, int, int, int)':
matrix.cpp:60:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=tl+tr>>1;
             ~~^~~
matrix.cpp: In function 'void update2(Node2*, int, int, int, int, int)':
matrix.cpp:75:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=tl+tr>>1;
             ~~^~~
matrix.cpp: In function 'int query2(Node2*, int, int, int, int, int, int)':
matrix.cpp:100:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=tl+tr>>1;
             ~~^~~
matrix.cpp: In function 'int main()':
matrix.cpp:109:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
matrix.cpp:111:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &M, &N);
     ~~~~~^~~~~~~~~~~~~~~~
matrix.cpp:114:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=N; i++) scanf("%d", &A[i].a);
                         ~~~~~^~~~~~~~~~~~~~~
matrix.cpp:115:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=N; i++) scanf("%d", &A[i].b), Vb.push_back(A[i].b);
                         ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
matrix.cpp:116:54: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     if(M==3) for(i=1; i<=N; i++) scanf("%d", &A[i].c), Vc.push_back(A[i].c);
                                  ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...