답안 #749279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
749279 2023-05-27T16:27:11 Z divad Fountain (eJOI20_fountain) C++14
30 / 100
197 ms 10572 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int NMAX = 1e5+2;
int n,q,d,c,r,v,vf,aib[NMAX],sol[NMAX];
pair<int, int> a[NMAX];
int stv[NMAX];
vector<pair<int, int>> queries[NMAX];
 
void update(int pos, int val){
    for(int i = pos; i <= n; i += (i&-i)){
        aib[i] += val;
    }
}
 
int query(int pos){
    int ans = 0;
    for(int i = pos; i > 0; i -= (i&-i)){
        ans += aib[i];
    }
    return ans;
}
 
int range(int st, int dr){
    return query(dr)-query(st-1);
}
 
signed main()
{
    cin >> n >> q;
    for(int i = 1; i <= n; i++){
        cin >> d >> c;
        a[i] = {d, c};
    }
    for(int i = 1; i <= q; i++){
        cin >> r >> v;
        queries[r].push_back({v, i});
    }
    for(int i = n; i >= 1; i--){
        while(vf > 0 && a[stv[vf]].first <= a[i].first){
            update(vf, -a[stv[vf]].second);
            vf--;
        }
        stv[++vf] = i;
        update(vf, a[i].second);
        for(auto [val, idx]: queries[i]){
            int st = 1, dr = vf;
            int len = 0;
            while(st <= dr){
                int mid = (st+dr)/2;
                if(range(vf-mid+1, vf) >= val){
                    len = mid;
                    dr = mid-1;
                }else{
                    st = mid+1;
                }
            }
            if(len == 0){
                sol[idx] = 0;
            }else{
                sol[idx] = stv[vf-len+1];
            }
        }
    }
    for(int i = 1; i <= q; i++){
        cout << sol[i] << "\n";
    }
    return 0;
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:46:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   46 |         for(auto [val, idx]: queries[i]){
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 3 ms 2668 KB Output is correct
3 Correct 2 ms 2676 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 4 ms 2804 KB Output is correct
6 Correct 4 ms 2772 KB Output is correct
7 Correct 4 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 197 ms 10572 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 3 ms 2668 KB Output is correct
3 Correct 2 ms 2676 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 4 ms 2804 KB Output is correct
6 Correct 4 ms 2772 KB Output is correct
7 Correct 4 ms 2772 KB Output is correct
8 Incorrect 197 ms 10572 KB Output isn't correct
9 Halted 0 ms 0 KB -