QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#749078 | #9742. 优秀的拆分 | _LSA_ | AC ✓ | 78ms | 38484kb | C++14 | 4.1kb | 2024-11-14 22:34:11 | 2024-11-14 22:34:15 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
using namespace std;
ll read(){
ll X = 0 ,r = 1;
char ch = getchar();
while(!isdigit(ch) && ch != '-') ch = getchar();
if(ch == '-') r = -1,ch = getchar();
while(isdigit(ch)) X = X*10+ch-'0',ch = getchar();
return X*r;
}
const int N = 2e5+10;
const int mod = 1e9+9;
int n,p[N];
struct node{
int mx;
ull cnt;
node(int x=0,int y=0){mx = x; cnt = y;}
node operator *(const node &o)const{
node res;
res.mx = max(mx,o.mx);
if(mx == res.mx) res.cnt += cnt;
if(o.mx == res.mx) res.cnt += o.cnt;
res.cnt %= mod;
return res;
}
};
struct Segment_Tree{
int L,R;
node t[N<<2];
#define ls rt<<1
#define rs rt<<1|1
inline void push_up(int rt){
t[rt].mx = max(t[ls].mx,t[rs].mx);
t[rt].cnt = 0;
if(t[ls].mx == t[rt].mx) t[rt].cnt += t[ls].cnt;
if(t[rs].mx == t[rt].mx) t[rt].cnt += t[rs].cnt;
t[rt].cnt %= mod;
}
void build(int rt,int l,int r){
t[rt].mx = t[rt].cnt = 0;
if(l == r){
return ;
}
int mid = (l+r) >> 1;
build(ls,l,mid);
build(rs,mid+1,r);
push_up(rt);
}
void update(int rt,int l,int r,int pos,node d){
if(l == r) return t[rt] = d,void();
int mid = (l+r) >> 1;
if(pos <= mid) update(ls,l,mid,pos,d);
if(pos > mid) update(rs,mid+1,r,pos,d);
push_up(rt);
}
node query(int rt,int l,int r,int ql,int qr){
if(ql <= l && r <= qr) return t[rt];
int mid = (l+r) >> 1;
if(mid < ql) return query(rs,mid+1,r,ql,qr);
if(qr <= mid) return query(ls,l,mid,ql,qr);
return query(ls,l,mid,ql,qr)*query(rs,mid+1,r,ql,qr);
}
void build(int l,int r){
L = l; R = r;
build(1,L,R);
}
void update(int pos,node d){
update(1,L,R,pos,d);
}
node query(int l,int r){
return query(1,L,R,l,r);
}
}T1,T2;
int f[N],g[N],u[N],v[N];
ull F[N],G[N],U[N],V[N];
/*
f_i 以 i 结尾的 LIS,F_i 以 i 结尾的 LIS数量
u_i 以 i 开头的 LIS,U_i 以 i 开头的 LIS数量
g_i 以 i 结尾的 LDS,G_i 以 i 结尾的 LDS数量
v_i 以 i 开头的 LDS,V_i 以 i 开头的 LDS数量
*/
void solve(){
n = read();
for(int i=1;i<=n;i++) p[i] = read();
T1.build(0,n);
T1.update(0,node(0,1));
for(int i=1;i<=n;i++){
node res = T1.query(0,p[i]-1);
res.mx++;
T1.update(p[i],res);
f[i] = res.mx,F[i] = res.cnt;
}
T2.build(1,n+1);
T2.update(n+1,node(0,1));
for(int i=1;i<=n;i++){
node res = T2.query(p[i]+1,n+1);
res.mx++;
T2.update(p[i],res);
g[i] = res.mx,G[i] = res.cnt;
}
int LIS = T1.query(0,n).mx,LDS = T2.query(1,n+1).mx;
ull ct1 = 0,ct2 = 0;
for(int i=1;i<=n;i++){
if(f[i] == LIS) (ct1 += F[i]) %= mod;
if(g[i] == LDS) (ct2 += G[i]) %= mod;
}
//
ull sum1 = ct1*ct2%mod;
T2.build(1,n+1);
T2.update(n+1,node(0,1));
for(int i=n;i;i--){
node res = T2.query(p[i]+1,n+1);
res.mx++;
T2.update(p[i],res);
u[i] = res.mx; U[i] = res.cnt;
}
T1.build(0,n);
T1.update(0,node(0,1));
for(int i=n;i;i--){
node res = T1.query(0,p[i]-1);
res.mx++;
T1.update(p[i],res);
v[i] = res.mx,V[i] = res.cnt;
}
ull sum2 = 0;
for(int i=1;i<=n;i++){
if(f[i]+u[i]-1 == LIS && g[i]+v[i]-1 == LDS){
(sum2 += F[i]*U[i]%mod*G[i]%mod*V[i]%mod)%=mod;
}
}
// if(n > 5e4){
// cout << ct1 << " " << ct2 << " " << ct1*ct2 << "\n";
// cout << LIS << " " << LDS << " " << sum1 << " " <<sum2 << "\n";
// }
if(sum1 == sum2) cout << LIS+LDS-1 << "\n";
else cout << LIS+LDS << "\n";
}
int main(){
int T = read();
while(T--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 36364kb
input:
3 5 3 5 1 4 2 4 1 2 4 3 5 3 5 2 1 4
output:
4 4 5
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 24ms
memory: 38484kb
input:
20000 2 2 1 10 6 10 2 7 9 3 8 4 1 5 9 3 6 4 5 8 9 2 7 1 7 3 7 6 4 1 5 2 7 7 2 3 6 5 1 4 5 4 1 3 2 5 9 6 7 5 3 8 1 9 2 4 3 1 2 3 8 7 2 4 6 1 8 3 5 7 4 2 6 3 1 7 5 8 1 7 3 4 2 5 6 8 2 1 2 10 10 2 3 8 6 9 1 4 7 5 4 3 2 1 4 9 7 5 3 4 1 2 9 6 8 7 2 4 5 1 6 7 3 10 3 1 10 4 9 5 6 8 2 7 5 1 2 5 3 4 6 2 6 5 ...
output:
2 8 8 6 7 5 7 3 6 6 8 2 8 4 7 6 9 5 6 7 7 8 9 7 8 1 5 6 5 7 3 3 4 3 6 7 6 1 6 5 1 8 6 8 6 6 2 3 2 6 8 5 6 5 7 3 2 7 7 6 3 1 3 1 8 7 8 4 1 1 8 7 7 2 7 2 1 9 2 5 6 3 5 6 8 6 2 2 1 6 6 7 8 3 1 8 6 10 2 8 8 4 6 3 8 8 2 4 1 3 5 8 9 1 7 7 2 6 7 4 8 1 2 5 3 1 8 6 7 1 9 7 5 7 3 8 1 5 5 6 4 5 4 1 6 2 7 6 1 7...
result:
ok 20000 lines
Test #3:
score: 0
Accepted
time: 59ms
memory: 37664kb
input:
20 895 97 29 511 535 178 149 710 846 37 191 684 504 309 528 524 189 659 42 337 688 213 343 859 433 606 445 693 608 232 585 577 313 759 746 612 341 480 875 610 222 28 637 11 91 796 261 296 333 377 871 275 552 788 371 763 862 522 322 447 126 492 694 799 620 842 394 434 706 460 479 240 241 676 502 749 ...
output:
115 165 331 171 112 204 247 226 239 114 231 241 57 229 371 243 347 120 62 352
result:
ok 20 lines
Test #4:
score: 0
Accepted
time: 78ms
memory: 37244kb
input:
2 66375 22486 8985 25896 9585 22371 18677 32794 51856 4976 20566 19519 11668 36820 19785 27213 14206 5728 54919 55392 20146 5373 20907 66131 64447 53265 22521 1393 31296 58406 54362 2294 13520 13660 59044 13345 44636 52942 37423 64998 54440 50291 61802 16224 5240 59589 52028 52268 6841 12466 65025 5...
output:
1000 317
result:
ok 2 lines
Test #5:
score: 0
Accepted
time: 38ms
memory: 37340kb
input:
1 32819 25454 18203 11285 15122 31242 9557 17292 31209 2640 19069 28006 6007 31106 8326 3990 27947 7492 12774 32211 1020 4848 30327 16472 8098 19636 1940 15391 18106 3008 22302 23602 4422 10926 27042 7619 27628 6755 30569 4901 25656 27915 32646 10310 24167 3546 24772 7010 14128 29519 24693 2421 3121...
output:
705
result:
ok single line: '705'
Test #6:
score: 0
Accepted
time: 23ms
memory: 36692kb
input:
200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 200000 lines
Extra Test:
score: 0
Extra Test Passed