답안 #460878

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
460878 2021-08-09T10:40:01 Z idas Fountain (eJOI20_fountain) C++14
60 / 100
1500 ms 292028 KB
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define SZ(x) ((int)((x).size()))
#define LE(vec) vec[vec.size()-1]
#define TSTS int t; cin >> t; while(t--)solve()

const int INF = 1e9;
const long long LINF = 1e18;
const long double PI = asin(1)*2;
const int MOD = 1e9+7;

using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
typedef long double ld;

void setIO()
{
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
 	freopen((s+".out").c_str(),"w",stdout);
}

const int N=1e5+10, Q=2e5+10;
int n, q, d[N], c[N];
vector<vector<ll>> p;
unordered_map<int, pii> con;
map<pii, int> rec;
bool v[N];

void pre(int i)
{
    vector<ll> nw;
    nw.PB(0); nw.PB(c[i]);
    int dl=d[i], in=p.size(), id=1;
    con[i]={in, id};
    rec[{in, id}]=i+1;
    id++;
    FOR(j, i+1, n)
    {
        if(d[j]>dl){
            nw.PB(LE(nw)+c[j]);
            con[j]={in, id};
            rec[{in, id}]=j+1;
            id++;
            v[j]=true;
            dl=d[j];
        }
    }
    p.PB(nw);
}

int main()
{
    setIO();
    cin >> n >> q;
    FOR(i, 0, n) cin >> d[i] >> c[i];

    FOR(i, 0, n)
    {
        if(!v[i]){
            pre(i);
        }
    }

    vector<pii> inf;
    FOR(i, 0, q)
    {
        int x; ll v;
        cin >> x >> v;
        int in=con[x-1].F, id=con[x-1].S;
        v+=p[in][id-1];
        int l=id, r=p[in].size();
        while(l<r){
            int m=(l+r)/2;
            if(p[in][m]<v) l=m+1;
            else r=m;
        }

        //inf.PB({in, l});
        cout << rec[{in, l}] << '\n';
    }

    /*for(auto x : p){
        for(auto y : x){
            cout << y << " ";
        }
        cout << '\n';
    }

    cout << '\n';
    for(auto[x, y] : inf){
        cout << x << " " << y << '\n';
    }*/
}

Compilation message

fountain.cpp: In function 'void setIO(std::string)':
fountain.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   freopen((s+".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   freopen((s+".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 16 ms 4216 KB Output is correct
7 Correct 4 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 220 ms 12944 KB Output is correct
2 Correct 258 ms 12148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 16 ms 4216 KB Output is correct
7 Correct 4 ms 588 KB Output is correct
8 Correct 220 ms 12944 KB Output is correct
9 Correct 258 ms 12148 KB Output is correct
10 Correct 3 ms 588 KB Output is correct
11 Execution timed out 1608 ms 292028 KB Time limit exceeded
12 Halted 0 ms 0 KB -