답안 #464206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
464206 2021-08-12T13:44:48 Z gesgha Fountain (eJOI20_fountain) C++17
30 / 100
7 ms 5600 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define fr(x, l, r) for(int x = l; x <= r; x++)
#define rf(x, l, r) for(int x = l; x >= r; x--)
#define fe(x, y) for(auto& x : y)

#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define pw(x) (ull(1) << ull(x))
#define all(x) (x).begin(),x.end()
#define sz(x) (int)x.size()
#define mt make_tuple
#define ve vector

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;
typedef pair <ld,ld> pld;

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

template<typename T>
bool umn(T& a, T b) { return a > b ? a = b, 1 : 0; }
template<typename T>
bool umx(T& a, T b) { return a < b ? a = b, 1 : 0; }

const ll inf = 1e18;
const int intf = 1e9;
const ll mod = 1e9 + 7;
const ld eps = 0.00000001;
const ll N  = 1e5 + 5;

ll d[N], c[N], p[N];

int main(){
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt","w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#else
//    freopen("mountains.in", "r", stdin);
//    freopen("mountains.out","w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int n, q;
    cin >> n >> q;
    if(n < 1e4){

        fr(i, 0, n - 1){
            cin >> d[i] >> c[i];
        }

        while(q--){
            int r, v;
            cin >> r >> v;
            r--;
            int di = d[r] - 1, ans = -1;
            fr(i, r, n - 1){
                if(di < d[i]){
                    di = d[i];
                    v -= c[i];
                }
                if(v <= 0){
                    ans = i;
                    break;
                }
            }
            cout << ans + 1 << endl;
        }
    }
    else{
        ve <ll> pr;
        pr.resize(n + 1, 0);
        fr(i, 1, n){
            int c, d;
            cin >> d >> c;
            pr[i] = pr[i - 1] + c;
            p[pr[i]] = i;
        }
        while(q --){
            int r, c;
            cin >> r >> c;
            auto it = upper_bound(all(pr), c + pr[r - 1]);
            cout << p[*it] << endl;
        }
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 6 ms 332 KB Output is correct
6 Correct 7 ms 332 KB Output is correct
7 Correct 4 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 5600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 6 ms 332 KB Output is correct
6 Correct 7 ms 332 KB Output is correct
7 Correct 4 ms 332 KB Output is correct
8 Runtime error 7 ms 5600 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -