結果
問題 | No.1703 Much Matching |
ユーザー |
![]() |
提出日時 | 2021-10-08 22:52:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 322 ms / 2,000 ms |
コード長 | 1,130 bytes |
コンパイル時間 | 688 ms |
コンパイル使用メモリ | 57,332 KB |
実行使用メモリ | 18,688 KB |
最終ジャッジ日時 | 2024-07-23 06:03:15 |
合計ジャッジ時間 | 4,150 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
#include <stdio.h>#include <vector>#include <algorithm>int C = 1;std::pair<int,int> P[1000010];int check[1000010];int next[1000010],prev[1000010];std::vector< std::pair<int,int> > temp;int main(){int a,b,c;scanf("%d%d%d",&a,&b,&c);for(int i=1;i<=c;i++) scanf("%d%d",&P[i].first,&P[i].second);std::sort(P+1,P+c+1);for(int i=1;i<=c;i++){if(P[i].first!=P[i-1].first) prev[i] = i;else prev[i] = prev[i-1];}for(int i=c;i>=1;i--){if(P[i].first!=P[i+1].first) next[i] = i;else next[i] = next[i+1];}for(int i=1;i<=c;i++){if(i==next[i]){for(int j=prev[i];j<=i;j++){int min = 1, max = C-1;int p = 0;while(min<=max){int h = (min+max)/2;if(check[h]<P[j].second){p = h;min = h+1;}else max = h-1;}temp.push_back(std::make_pair(p+1,P[j].second));}while(!temp.empty()){std::pair<int,int> t = temp.back();temp.pop_back();if(t.first==C) C++, check[t.first] = t.second;else check[t.first] = check[t.first]<t.second?check[t.first]:t.second;}}}printf("%d",C-1);}