QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#885564#9306. Tree Tweakinggyydp123_LIMAC ✓4ms6488kbC++201.6kb2025-02-06 16:18:562025-02-06 16:18:57

Judging History

This is the latest submission verdict.

  • [2025-02-06 16:18:57]
  • Judged
  • Verdict: AC
  • Time: 4ms
  • Memory: 6488kb
  • [2025-02-06 16:18:56]
  • Submitted

answer

//Start: 2025-02-06 16:03:59
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=(j);i<=(k);++i)
#define ForDown(i,j,k) for(int i=(j);i>=(k);--i)
#define Debug(fmt, args...) fprintf(stderr,"(func %s, line #%d): " fmt, __func__, __LINE__, ##args),fflush(stderr)
#define debug(fmt, args...) fprintf(stderr,fmt,##args),fflush(stderr)
#define within :
#define LJY main
using namespace std;
typedef long long ll;
const int N=1e5+5,M=205;
const ll inf=1e18;
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
inline int read(){
  char ch=getchar();int x=0,f=1;
  while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
  while(ch>='0'&&ch<='9')
    x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
  return x*f;
}
int n,a[N],pos[N],l,r;
int stk[N],tp,ls[N],rs[N],rt,siz[N];
int s[M],tot;ll f[M][M];
void dfs(int u){
  if(!u||pos[u]>r){tot++;s[tot]=s[tot-1]+siz[u];return;}
  dfs(ls[u]);dfs(rs[u]);
}
ll solve(int x){
  tot=0;dfs(x);
  ForDown(l,tot,1) For(r,l+1,tot){
    f[l][r]=inf;
    For(k,l,r-1) f[l][r]=min(f[l][r],f[l][k]+f[k+1][r]);
    f[l][r]+=r-l+s[r]-s[l-1];
  }return f[1][tot];
}
signed LJY(){
  n=read();For(i,1,n) pos[a[i]=read()]=i;l=read(),r=read();
  For(i,1,n){
    int lst=tp;
    while(pos[stk[tp]]>pos[i]) tp--;
    if(lst!=tp) ls[i]=stk[tp+1];
    if(tp) rs[stk[tp]]=i;else rt=i;stk[++tp]=i;
  }ForDown(i,n,1) siz[a[i]]=siz[ls[a[i]]]+siz[rs[a[i]]]+1;
  ll ans=(l==1?solve(a[1]):0);
  For(i,1,n) if(pos[i]<l||pos[i]>r){
    ans+=siz[i];
    if(pos[ls[i]]>=l&&pos[ls[i]]<=r) ans+=solve(ls[i]);
    if(pos[rs[i]]>=l&&pos[rs[i]]<=r) ans+=solve(rs[i]);
  }printf("%lld",ans);
  return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3840kb

input:

8
2 4 5 7 1 3 8 6
3 6

output:

24

result:

ok 1 number(s): "24"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

5
5 1 2 3 4
3 5

output:

14

result:

ok 1 number(s): "14"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3712kb

input:

7
3 2 4 6 7 5 1
1 7

output:

17

result:

ok 1 number(s): "17"

Test #4:

score: 0
Accepted
time: 3ms
memory: 6480kb

input:

97865
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 99 100 10...

output:

4779092019

result:

ok 1 number(s): "4779092019"

Test #5:

score: 0
Accepted
time: 3ms
memory: 6228kb

input:

90053
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 176 177 178 179 180 181 182 183 184 185 186 187 ...

output:

4045831111

result:

ok 1 number(s): "4045831111"

Test #6:

score: 0
Accepted
time: 2ms
memory: 6228kb

input:

100000
1 2 3 4 5 6 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 1...

output:

4990056230

result:

ok 1 number(s): "4990056230"

Test #7:

score: 0
Accepted
time: 3ms
memory: 6224kb

input:

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 99 100 1...

output:

4990482700

result:

ok 1 number(s): "4990482700"

Test #8:

score: 0
Accepted
time: 3ms
memory: 5760kb

input:

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 99 100 1...

output:

4994277470

result:

ok 1 number(s): "4994277470"

Test #9:

score: 0
Accepted
time: 3ms
memory: 5888kb

input:

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 99 100 1...

output:

4991797502

result:

ok 1 number(s): "4991797502"

Test #10:

score: 0
Accepted
time: 3ms
memory: 6016kb

input:

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 99 100 1...

output:

4992096630

result:

ok 1 number(s): "4992096630"

Test #11:

score: 0
Accepted
time: 2ms
memory: 6360kb

input:

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 99 100 1...

output:

4991378130

result:

ok 1 number(s): "4991378130"

Test #12:

score: 0
Accepted
time: 3ms
memory: 6224kb

input:

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 197 198 199 20...

output:

4990065230

result:

ok 1 number(s): "4990065230"

Test #13:

score: 0
Accepted
time: 3ms
memory: 6488kb

input:

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 99 100 1...

output:

4991613286

result:

ok 1 number(s): "4991613286"

Test #14:

score: 0
Accepted
time: 2ms
memory: 5888kb

input:

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 99 100 1...

output:

4992365820

result:

ok 1 number(s): "4992365820"

Test #15:

score: 0
Accepted
time: 1ms
memory: 5760kb

input:

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 99 100 1...

output:

4992762661

result:

ok 1 number(s): "4992762661"

Test #16:

score: 0
Accepted
time: 2ms
memory: 5760kb

input:

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 99 100 1...

output:

4991912205

result:

ok 1 number(s): "4991912205"

Test #17:

score: 0
Accepted
time: 4ms
memory: 5760kb

input:

100000
26024 93049 7783 16602 86687 42006 24967 72232 61703 87842 99276 55658 26859 5207 64343 56070 77523 56145 27208 12527 36727 50469 48268 77211 13316 85211 62658 86029 1232 54191 32511 41813 64157 23763 98521 43414 63843 30732 55482 73178 78314 59291 36957 70984 11955 57167 17167 92685 90920 85...

output:

2157797

result:

ok 1 number(s): "2157797"

Test #18:

score: 0
Accepted
time: 2ms
memory: 5888kb

input:

100000
97072 1764 47263 75748 40600 56773 71415 43764 7532 47399 11820 40198 9380 89231 57468 80933 13541 68389 63484 65806 35296 7725 39412 79510 22299 7390 48316 15794 63673 93495 57387 36081 64069 59878 49424 24382 73210 2744 16587 40382 40988 87804 43018 94339 7458 67657 90106 33631 16504 50502 ...

output:

2255515

result:

ok 1 number(s): "2255515"

Test #19:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

1
1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #20:

score: 0
Accepted
time: 0ms
memory: 4096kb

input:

1000
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 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 ...

output:

348066

result:

ok 1 number(s): "348066"

Test #21:

score: 0
Accepted
time: 1ms
memory: 4224kb

input:

500
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 99 100 101 ...

output:

69703

result:

ok 1 number(s): "69703"

Test #22:

score: 0
Accepted
time: 1ms
memory: 4096kb

input:

3000
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 99 100 101...

output:

4032831

result:

ok 1 number(s): "4032831"

Test #23:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

600
119 230 578 154 597 110 583 339 235 139 487 45 68 353 304 16 587 407 462 408 514 421 540 305 117 434 269 137 130 264 441 298 565 484 527 532 185 535 263 128 525 203 187 469 422 326 195 35 193 317 126 29 250 334 318 411 543 555 382 360 366 268 465 136 142 596 506 361 120 105 529 295 423 223 352 5...

output:

6510

result:

ok 1 number(s): "6510"

Test #24:

score: 0
Accepted
time: 0ms
memory: 6228kb

input:

200
28 3 116 107 8 112 33 45 49 168 76 120 194 110 15 172 66 75 60 11 147 4 146 58 27 131 38 197 127 9 20 19 61 186 103 138 97 157 73 77 65 56 101 57 25 185 176 22 47 117 181 99 179 149 17 40 53 166 62 130 32 187 104 160 92 170 87 178 54 37 174 191 144 151 26 69 43 74 190 105 162 111 145 169 142 46 ...

output:

1353

result:

ok 1 number(s): "1353"

Test #25:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

10000
2676 8408 8091 1814 4456 8748 3127 9488 5144 2692 6920 4388 8130 7751 9478 8214 5660 8945 2232 1556 4030 2633 1649 7198 2491 7557 1909 7613 4350 8010 6909 182 9058 607 4147 1211 4805 7647 235 7928 5751 6576 7874 8762 592 1623 8981 6247 5865 2991 2928 4647 3130 8500 3290 7670 6793 7572 7492 248...

output:

164638

result:

ok 1 number(s): "164638"

Extra Test:

score: 0
Extra Test Passed