답안 #711270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711270 2023-03-16T12:17:06 Z ToroTN Bigger segments (IZhO19_segments) C++14
100 / 100
423 ms 41588 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define X first
#define Y second
set<pair<ll,ll> > s;
set<pair<ll,ll> > :: iterator it;
vector<pair<ll,ll> > v;
ll n,a,qs[500005],sum[500005],dp[500005],from,cal;
ll query(ll l,ll r)
{
    if(l>r)return 0;
    return qs[r]-qs[l-1];
}
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a);
        qs[i]=qs[i-1]+a;
        dp[i]=1e18;
    }
    s.insert({0,0});
    for(int i=1;i<=n;i++)
    {
        it=s.upper_bound({qs[i],1e18});
        --it;
        from=(*it).Y;
        dp[i]=dp[from]+1;
        cal=qs[i]+query(from+1,i);
        s.insert({cal,i});
        it=s.upper_bound({cal,i});
        v.clear();
        while(it!=s.end())
        {
            v.pb(*it);
            ++it;
        }
        for(auto [x,y]:v)s.erase({x,y});
        it=s.find({cal,i});
        if(it!=s.begin())
        {
            --it;
            if((*it).X==cal)s.erase(*it);
        }
    }
    printf("%lld\n",dp[n]);
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:41:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |         for(auto [x,y]:v)s.erase({x,y});
      |                  ^
segments.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
segments.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%lld",&a);
      |         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 304 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 304 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 304 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 608 KB Output is correct
35 Correct 2 ms 576 KB Output is correct
36 Correct 2 ms 448 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 304 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 608 KB Output is correct
35 Correct 2 ms 576 KB Output is correct
36 Correct 2 ms 448 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 54 ms 8508 KB Output is correct
47 Correct 48 ms 6644 KB Output is correct
48 Correct 51 ms 3180 KB Output is correct
49 Correct 74 ms 6600 KB Output is correct
50 Correct 70 ms 9120 KB Output is correct
51 Correct 57 ms 7760 KB Output is correct
52 Correct 28 ms 4032 KB Output is correct
53 Correct 17 ms 2516 KB Output is correct
54 Correct 52 ms 6604 KB Output is correct
55 Correct 68 ms 8424 KB Output is correct
56 Correct 64 ms 8524 KB Output is correct
57 Correct 67 ms 8772 KB Output is correct
58 Correct 57 ms 8024 KB Output is correct
59 Correct 67 ms 8804 KB Output is correct
60 Correct 64 ms 8580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 304 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 608 KB Output is correct
35 Correct 2 ms 576 KB Output is correct
36 Correct 2 ms 448 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 54 ms 8508 KB Output is correct
47 Correct 48 ms 6644 KB Output is correct
48 Correct 51 ms 3180 KB Output is correct
49 Correct 74 ms 6600 KB Output is correct
50 Correct 70 ms 9120 KB Output is correct
51 Correct 57 ms 7760 KB Output is correct
52 Correct 28 ms 4032 KB Output is correct
53 Correct 17 ms 2516 KB Output is correct
54 Correct 52 ms 6604 KB Output is correct
55 Correct 68 ms 8424 KB Output is correct
56 Correct 64 ms 8524 KB Output is correct
57 Correct 67 ms 8772 KB Output is correct
58 Correct 57 ms 8024 KB Output is correct
59 Correct 67 ms 8804 KB Output is correct
60 Correct 64 ms 8580 KB Output is correct
61 Correct 332 ms 41332 KB Output is correct
62 Correct 372 ms 41472 KB Output is correct
63 Correct 275 ms 33452 KB Output is correct
64 Correct 389 ms 16640 KB Output is correct
65 Correct 395 ms 41588 KB Output is correct
66 Correct 331 ms 35116 KB Output is correct
67 Correct 259 ms 28632 KB Output is correct
68 Correct 120 ms 15280 KB Output is correct
69 Correct 301 ms 31876 KB Output is correct
70 Correct 423 ms 39052 KB Output is correct
71 Correct 391 ms 41288 KB Output is correct
72 Correct 400 ms 37428 KB Output is correct
73 Correct 374 ms 38072 KB Output is correct
74 Correct 376 ms 41548 KB Output is correct
75 Correct 400 ms 41568 KB Output is correct