Submission #127158

#TimeUsernameProblemLanguageResultExecution timeMemory
127158arnold518조화행렬 (KOI18_matrix)C++14
100 / 100
3849 ms601368 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 c<p.c; } }; Data A[MAXN+10]; struct Node1 { Node1() : val(0), lc(NULL), rc(NULL) {} int val; Node1 *lc, *rc; }; Node1 *tree[MAXN+10]; 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(int ypos, int xpos, int val) { for(int i=ypos; i<=N; i+=(i&-i)) update1(tree[i], 1, N, xpos, val); } int query2(int ypos, int xpos) { int ret=0; for(int i=ypos; i>0; i-=(i&-i)) ret=max(ret, query1(tree[i], 1, N, 1, xpos)); return ret; } int main() { int i, j; scanf("%d%d", &M, &N); for(i=1; i<=N; i++) tree[i]=new Node1(); vector<int> Va, Vb; for(i=1; i<=N; i++) scanf("%d", &A[i].a), Va.push_back(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); else for(i=1; i<=N; i++) A[i].c=A[i].a; sort(Va.begin(), Va.end()); sort(Vb.begin(), Vb.end()); for(i=1; i<=N; i++) A[i].a=lower_bound(Va.begin(), Va.end(), A[i].a)-Va.begin()+1; for(i=1; i<=N; i++) A[i].b=lower_bound(Vb.begin(), Vb.end(), A[i].b)-Vb.begin()+1; sort(A+1, A+N+1); for(i=1; i<=N; i++) { int now=query2(A[i].a, A[i].b)+1; ans=max(ans, now); update2(A[i].a, A[i].b, now); } printf("%d", ans); }

Compilation message (stderr)

matrix.cpp: In function 'void update1(Node1*, int, int, int, int)':
matrix.cpp:33: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:53:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=tl+tr>>1;
             ~~^~~
matrix.cpp: In function 'int main()':
matrix.cpp:65:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
matrix.cpp:67: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:71: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].a), Va.push_back(A[i].a);
                         ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
matrix.cpp:72: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:73:39: 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);
                                  ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...