답안 #334095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334095 2020-12-08T10:25:32 Z beksultan04 Money (IZhO17_money) C++14
0 / 100
1 ms 364 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]+=1;

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

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,sum=0,l;
    scan1(n)
    for (i=1;i<=n;++i)scan1(q[i])
    update(1,1,1000000,q[1]);
    vector<int> v;
    v.pb(q[1]);
    for (i=2;i<=n;++i){
        if (q[i] < q[i-1]){
            ans++;
            l = q[i];
            sum=0;
            while (v.size()>0){
                int x = v.back();
                update(1,1,1000000,x);
                v.pop_back();
            }
            v.pb(q[i]);
        }
        else {
            int x = get_ans(1,1,1000000,l+1,q[i]-1);
            if (x > 0){
                l = q[i];
                ans++;
                while (v.size()>0){
                    int x = v.back();
                    update(1,1,1000000,x);
                    v.pop_back();
                }
                v.pb(q[i]);
            }
            else {
                sum++;
                v.pb(q[i]);
            }
        }

    }

    cout <<ans+1;
}


















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:34:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |     int m = l+r>>1;
      |             ~^~
money.cpp: At global scope:
money.cpp:38:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main(){
      |      ^
money.cpp: In function 'int main()':
money.cpp:39:11: warning: unused variable 'j' [-Wunused-variable]
   39 |     int n,j,i,ans=0,sum=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:40:5: note: in expansion of macro 'scan1'
   40 |     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:41:23: note: in expansion of macro 'scan1'
   41 |     for (i=1;i<=n;++i)scan1(q[i])
      |                       ^~~~~
money.cpp:58:28: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |             int x = get_ans(1,1,1000000,l+1,q[i]-1);
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -