QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#276719 | #6358. 序列 | SoyTony | 100 ✓ | 146ms | 6152kb | C++14 | 3.0kb | 2023-12-06 10:03:02 | 2023-12-06 10:03:03 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int maxn=1e5+10;
const int maxm=1e6+10;
const ll mod=1e9;
const ll base=1e8;
const ull base1=10007;
const ull base2=19260817;
const int maxxn=0x3f3f3f3f;
const int minxn=-0x3f3f3f3f;
const db inf=1e13;
const db eps=1e-9;
inline ll read(){
ll x=0,w=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
return x*w;
}
int n,m;
struct node{
int id;
int val,mx,mn;
}a[maxn];
bool cmp_val(node x,node y){
return x.val<y.val;
}
bool cmp_mx(node x,node y){
return x.mx<y.mx;
}
bool cmp_id(node x,node y){
return x.id<y.id;
}
struct BinaryIndexTree{
int num[maxn];
BinaryIndexTree(){
memset(num,-0x3f,sizeof(num));
}
inline int lowbit(int x){return x&-x;}
inline void update(int x,int k){
while(x<=n){
num[x]=max(num[x],k);
x+=lowbit(x);
}
}
inline int query(int x){
int res=-0x3f3f3f3f;
while(x){
res=max(res,num[x]);
x-=lowbit(x);
}
return res;
}
inline void init(int x){
while(x<=n){
if(num[x]!=-0x3f3f3f3f) num[x]=-0x3f3f3f3f;
else return;
x+=lowbit(x);
}
}
}B;
int dp[maxn];
void cdq(int l,int r){
#define mid ((l+r)>>1)
if(l==r){
dp[l]=max(dp[l],1);
return;
}
cdq(l,mid);
//printf("%d %d\n",l,r);
sort(a+l,a+mid+1,cmp_mx);
sort(a+mid+1,a+r+1,cmp_val);
int i=l,j=mid+1;
while(i<=mid&&j<=r){
if(a[i].mx<=a[j].val){
B.update(a[i].val,dp[a[i].id]);
++i;
}
else{
dp[a[j].id]=max(dp[a[j].id],B.query(a[j].mn)+1);
//printf("%d\n",dp[a[j].id]);
++j;
}
}
while(j<=r){
dp[a[j].id]=max(dp[a[j].id],B.query(a[j].mn)+1);
//printf("%d\n",dp[a[j].id]);
++j;
}
while(i>=l){
B.init(a[i].val);
--i;
}
sort(a+l,a+r+1,cmp_id);
cdq(mid+1,r);
#undef mid
}
int ans;
int main(){
n=read(),m=read();
for(int i=1;i<=n;++i){
a[i].id=i,a[i].val=a[i].mx=a[i].mn=read();
dp[i]=-0x3f3f3f3f;
}
for(int i=1;i<=m;++i){
int x=read(),k=read();
a[x].mx=max(a[x].mx,k);
a[x].mn=min(a[x].mn,k);
}
/*for(int i=1;i<=n;++i){
printf("%d %d %d %d\n",i,a[i].val,a[i].mx,a[i].mn);
}*/
cdq(1,n);
for(int i=1;i<=n;++i){
//printf("%d\n",dp[i]);
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
return 0;
}
详细
Test #1:
score: 10
Accepted
time: 1ms
memory: 5944kb
input:
300 300 11 165 112 67 271 244 74 130 195 266 29 143 92 2 137 40 160 19 186 214 36 182 190 169 107 22 253 268 105 131 202 129 21 6 105 6 5 230 239 162 100 185 278 292 194 245 58 111 69 143 248 107 228 284 296 152 107 91 276 272 17 12 20 61 39 266 248 299 161 28 74 263 41 144 27 17 194 286 34 147 37 1...
output:
19
result:
ok 1 number(s): "19"
Test #2:
score: 10
Accepted
time: 1ms
memory: 4212kb
input:
300 300 39 61 63 205 50 185 50 148 146 14 195 209 119 123 185 58 174 35 152 62 154 117 85 209 59 260 102 139 75 30 149 92 22 274 104 191 127 38 67 299 121 285 9 295 140 25 129 34 98 224 211 125 213 113 221 165 9 287 255 84 17 182 222 110 55 184 162 184 85 13 172 193 134 108 193 79 205 183 93 182 256...
output:
22
result:
ok 1 number(s): "22"
Test #3:
score: 10
Accepted
time: 3ms
memory: 4288kb
input:
3000 3000 382 2833 2401 713 1798 843 2465 2372 2722 1193 309 2019 2400 1234 2207 583 46 156 966 662 214 2047 210 787 1372 2655 1565 2357 1119 2600 1887 327 1499 663 2902 556 2641 2600 1282 2582 140 1457 2921 2220 2801 2642 1744 525 193 683 2374 341 2941 511 1107 1899 1257 623 1110 790 1627 2141 248 ...
output:
61
result:
ok 1 number(s): "61"
Test #4:
score: 10
Accepted
time: 3ms
memory: 4208kb
input:
3000 3000 2224 1680 1604 2720 2437 181 2729 52 672 1212 1008 1068 1117 1486 2129 1660 420 1530 1065 1334 2738 1473 2876 847 497 312 2512 2437 1074 22 1234 695 1924 2265 174 2060 927 1906 874 2214 648 1607 1044 2648 1123 1112 1524 2836 2063 531 792 2318 1542 528 2821 2192 60 564 55 208 1724 1196 1601...
output:
63
result:
ok 1 number(s): "63"
Test #5:
score: 10
Accepted
time: 0ms
memory: 4252kb
input:
3000 3000 452 676 955 1058 1863 1622 905 1270 2423 2460 1121 1787 1144 1007 77 1378 787 2446 2778 1782 1656 208 2418 887 149 1750 2908 2608 1044 1421 34 411 1325 1686 473 2298 2549 2561 1602 1204 1869 1707 1675 2051 1122 2445 2142 1259 1192 665 2855 2636 2727 657 1846 2152 262 760 1587 1820 2024 256...
output:
61
result:
ok 1 number(s): "61"
Test #6:
score: 10
Accepted
time: 137ms
memory: 6144kb
input:
100000 100000 52226 53242 35439 90379 97033 86655 97539 68113 96956 4670 55515 35991 16837 97641 15202 32228 84177 58895 51972 87393 20806 61184 96316 71821 80407 19801 6819 22132 99954 52045 21047 52159 63805 72006 52990 23621 62001 67430 82802 992 41717 72462 10162 48148 98867 21127 51859 24214 54...
output:
379
result:
ok 1 number(s): "379"
Test #7:
score: 10
Accepted
time: 142ms
memory: 6144kb
input:
100000 100000 2647 95342 34717 37706 56529 20471 80171 53453 63431 66856 81541 66839 3019 26767 39163 16090 63864 54082 4845 15229 70068 93397 82149 12351 1793 65306 2469 95672 88108 70756 67397 8343 20694 59807 73479 72873 37644 53936 41598 93808 77618 53537 47047 38862 91675 96362 60249 39193 7495...
output:
384
result:
ok 1 number(s): "384"
Test #8:
score: 10
Accepted
time: 146ms
memory: 6152kb
input:
100000 100000 53068 21089 17642 85033 99672 70640 62803 38793 29906 29042 91214 14040 5554 55893 79477 16305 43551 49269 74071 59418 19330 25610 51629 52881 39532 94458 81766 69212 59909 89467 97394 64527 61230 47608 77615 22125 13287 24089 394 86624 29872 34612 83932 29576 836 71597 68639 70525 118...
output:
375
result:
ok 1 number(s): "375"
Test #9:
score: 10
Accepted
time: 141ms
memory: 6140kb
input:
100000 100000 86682 71587 34141 88702 33885 93184 17891 73255 18458 37166 20094 6723 7244 41977 95451 77664 24558 12727 31751 44642 24289 8301 19753 79901 31358 52677 67964 62474 79894 12843 28294 12885 4607 6142 41588 93744 91598 98740 6258 20619 70159 88662 19424 954 84512 55087 35448 91413 8631 6...
output:
372
result:
ok 1 number(s): "372"
Test #10:
score: 10
Accepted
time: 44ms
memory: 6152kb
input:
100000 100000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...
output:
100000
result:
ok 1 number(s): "100000"