Submission #460553

#TimeUsernameProblemLanguageResultExecution timeMemory
460553idasFountain (eJOI20_fountain)C++11
30 / 100
94 ms5192 KiB
#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], p[N];

int main()
{
    setIO();
    cin >> n >> q;
    FOR(i, 0, n) cin >> d[i] >> c[i];
    FOR(i, 1, n+1)
    {
        p[i]=p[i-1]+c[i-1];
    }

    FOR(i, 0, q)
    {
        int x, q;
        cin >> x >> q;
        q+=p[x-1];
        int l=x, r=n+1;
        while(l<r){
            int m=(l+r)/2;
            if(p[m]<q) l=m+1;
            else r=m;
        }

        cout << (l>n?0:l) << "\n";
    }
}

Compilation message (stderr)

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);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...