답안 #334139

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334139 2020-12-08T12:02:51 Z beksultan04 Money (IZhO17_money) C++14
100 / 100
744 ms 31468 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define pb push_back
#define endi puts("");
const int N = 1e6+12,INF=1e9+7;
int q[N],der[4*N];

void update(int v,int l,int r,int x){
    if (l==r)
        der[v]++;

    else {
        int m = l+r>>1;
        if (x <= m)
            update((v<<1),l,m,x);
        else
            update((v<<1)+1,m+1,r,x);
        der[v]=der[v<<1]+der[(v<<1)+1];
    }
}

int get_ans(int v,int l,int r,int ql,int qr){
    if (r <= ql || qr <= l || ql > qr)ret 0;
    if (ql < l && r < qr)ret der[v];
    int m = l+r>>1;
    ret get_ans(v<<1,l,m,ql,qr)+get_ans((v<<1)+1,m+1,r,ql,qr);
}

main(){
    int n,j,i,ans=0,l;
    scan1(n)
    for (i=1;i<=n;++i)scan1(q[i])
    l=1;
    for (i=1;i<=n;++i){
        int x = get_ans(1,1,1000000,q[l],q[i+1]);
        if (x || q[i] > q[i+1]){
            ans++;
            while (l <= i){
                update(1,1,1000000,q[l++]);
            }
        }
    }

    cout <<ans;
}


















Compilation message

money.cpp: In function 'void update(long long int, long long int, long long int, long long int)':
money.cpp:23:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |         int m = l+r>>1;
      |                 ~^~
money.cpp: In function 'long long int get_ans(long long int, long long int, long long int, long long int, long long int)':
money.cpp:35:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |     int m = l+r>>1;
      |             ~^~
money.cpp: At global scope:
money.cpp:39:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   39 | main(){
      |      ^
money.cpp: In function 'int main()':
money.cpp:40:11: warning: unused variable 'j' [-Wunused-variable]
   40 |     int n,j,i,ans=0,l;
      |           ^
money.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
money.cpp:41:5: note: in expansion of macro 'scan1'
   41 |     scan1(n)
      |     ^~~~~
money.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
money.cpp:42:23: note: in expansion of macro 'scan1'
   42 |     for (i=1;i<=n;++i)scan1(q[i])
      |                       ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 1 ms 620 KB Output is correct
19 Correct 1 ms 620 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 620 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 876 KB Output is correct
26 Correct 1 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 1 ms 620 KB Output is correct
19 Correct 1 ms 620 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 620 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 876 KB Output is correct
26 Correct 1 ms 748 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 620 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 620 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 3 ms 3436 KB Output is correct
38 Correct 3 ms 3436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 1 ms 620 KB Output is correct
19 Correct 1 ms 620 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 620 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 876 KB Output is correct
26 Correct 1 ms 748 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 620 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 620 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 3 ms 3436 KB Output is correct
38 Correct 3 ms 3436 KB Output is correct
39 Correct 189 ms 7444 KB Output is correct
40 Correct 328 ms 12268 KB Output is correct
41 Correct 151 ms 6124 KB Output is correct
42 Correct 142 ms 5996 KB Output is correct
43 Correct 105 ms 4460 KB Output is correct
44 Correct 409 ms 15340 KB Output is correct
45 Correct 400 ms 15212 KB Output is correct
46 Correct 402 ms 15468 KB Output is correct
47 Correct 431 ms 15084 KB Output is correct
48 Correct 381 ms 15212 KB Output is correct
49 Correct 585 ms 31468 KB Output is correct
50 Correct 579 ms 31468 KB Output is correct
51 Correct 589 ms 31468 KB Output is correct
52 Correct 576 ms 31468 KB Output is correct
53 Correct 589 ms 31468 KB Output is correct
54 Correct 582 ms 31468 KB Output is correct
55 Correct 732 ms 31468 KB Output is correct
56 Correct 744 ms 31468 KB Output is correct
57 Correct 731 ms 31468 KB Output is correct
58 Correct 741 ms 31384 KB Output is correct
59 Correct 737 ms 31340 KB Output is correct
60 Correct 734 ms 31340 KB Output is correct
61 Correct 734 ms 31468 KB Output is correct
62 Correct 736 ms 31468 KB Output is correct