답안 #987706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987706 2024-05-23T11:42:15 Z 0pt1mus23 Money (IZhO17_money) C++14
0 / 100
1 ms 348 KB
#pragma GCC optimize("O3", "inline")
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define ins insert
#define pb push_back
#define int long long
#define pii pair<int, int>
#define endl '\n'
#define drop(x) cout<<(x)<<endl;return;
#define reach cerr << "reached >.<!" << endl;
/*
    m : 11059739 -> l ~23
    p : 4567896467
*/
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9 + 7, sze = 1e6 + 5, inf = LLONG_MAX, prime = 2333;

//\\
dp / binary search / greedy / sprase table / segment tree 
//

int T[sze];

void upd(int node,int v){
    node++;
    while(node<sze){
        T[node]+=v;
        node += (node & -node);
    }
}

int query(int node){
    node++;
    int sum=0;
    while(node>0){
        sum+=T[node];
        node -= (node & -node);
    }
    return sum;
}

int query(int l,int r){
    return query(r) - query(l-1);
}

void gkd(){
    int n;
    cin>>n;
    vector<int> arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    map<int,int> used;
    int ans=0;
    for(int i=0;i<n;i++){
        if(!used[i]){
            ans++;
            used[i]=1;
            vector<int> up;
            up.pb(arr[i]);

            for(int j=i+1;j<n;j++){
                if(arr[j-1]>arr[j] || query(arr[i]+1, arr[j]-1)){
                    break;
                }
                used[j]=1;
                up.pb(arr[j]);
            }
            for(auto v:up){
                upd(v,1);
            }
        }
    }
    drop(ans);
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int tt = 1; //cin>>tt;
    while (tt--)gkd();
}

Compilation message

money.cpp:19:1: warning: multi-line comment [-Wcomment]
   19 | //\\
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 1 ms 344 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 1 ms 344 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 1 ms 344 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 1 ms 344 KB Output isn't correct
9 Halted 0 ms 0 KB -