Submission #922276

#TimeUsernameProblemLanguageResultExecution timeMemory
922276panFountain (eJOI20_fountain)C++17
100 / 100
373 ms46932 KiB
#include <bits/stdc++.h> //#include "bits_stdc++.h" #include <stdio.h> #include <algorithm> #include <memory.h> #define f first #define s second #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define input(x) scanf("%lld", &x); #define print(x, y) printf("%lld%c", x, y); #define show(x) cerr << #x << " is " << x << endl; #define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl; #define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl; using namespace std; typedef long long ll; typedef long double ld; typedef pair<ld, ll> pd; typedef pair<string, ll> psl; typedef pair<ll, ll> pi; typedef pair<ll, pi> pii; ll n, q, tem, a, b; ll const INF = 1e12; ll twok[100005][25], summ[100005][25]; pi fountain[100005]; void init2k() { for (ll k=1; k<=20; k++) for (ll x=1; x<=n; x++){twok[x][k] = n+1, summ[x][k] = INF;} for (ll k=1; k<=20; k++) { for (ll x=1; x<=n; x++) { if (twok[x][k-1]==n+1) continue; twok[x][k] = twok[twok[x][k-1]][k-1]; summ[x][k] = summ[x][k-1] + summ[twok[x][k-1]][k-1]; } } } int main() { input(n); input(q); deque<pi> que; for (ll i=1; i<=n; ++i) { input(a); input(b); fountain[i] = mp(a,b); while (que.size() && que.back().f<a) { twok[que.back().s][0] = i; summ[que.back().s][0] = b; que.pop_back(); } que.push_back(mp(a, i)); } while (que.size()) {twok[que.back().s][0] = n+1, summ[que.back().s][0] = INF; que.pop_back();} init2k(); while (q--) { input(a); input(b); //show2(a,b); b-=fountain[a].s; if (b<=0) {print(a, '\n'); continue;} for (ll k=20; k>=0; --k) { if (b>summ[a][k]) { b-=summ[a][k]; a = twok[a][k]; //show3(k, a,b); } } if (twok[a][0]==n+1) {print(0LL, '\n');} else {print(twok[a][0], '\n');} } return 0; }

Compilation message (stderr)

fountain.cpp: In function 'int main()':
fountain.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
fountain.cpp:44:2: note: in expansion of macro 'input'
   44 |  input(n); input(q);
      |  ^~~~~
fountain.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
fountain.cpp:44:12: note: in expansion of macro 'input'
   44 |  input(n); input(q);
      |            ^~~~~
fountain.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
fountain.cpp:48:3: note: in expansion of macro 'input'
   48 |   input(a); input(b);
      |   ^~~~~
fountain.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
fountain.cpp:48:13: note: in expansion of macro 'input'
   48 |   input(a); input(b);
      |             ^~~~~
fountain.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
fountain.cpp:62:3: note: in expansion of macro 'input'
   62 |   input(a); input(b);
      |   ^~~~~
fountain.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
fountain.cpp:62:13: note: in expansion of macro 'input'
   62 |   input(a); input(b);
      |             ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...