제출 #1312487

#제출 시각아이디문제언어결과실행 시간메모리
1312487_TemirhanFountain (eJOI20_fountain)C++20
100 / 100
244 ms36140 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC optimize("Ofast,unroll-loops,inline-functions,no-stack-protector,03") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native") #pragma clang loop vectorize(enable) #pragma clang loop interleave(enable) #define int long long #define sz(x) (int)x.size() #define F first #define S second #define pb push_back #define nl '\n' #define o_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef pair<int, int> pii; void file( string s = "" ) { if( s.empty() ) return; freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int N = 2e5 + 2; const int N1 = 1e6 + 2; const int inf = 1e9 + 2; const int INF = 1e18 + 2; const int mod = 1e9 + 7; int T = 1, n, q, c[N], d[N], up[N][20], sum[N][20]; void solve() { cin >>n >>q; for( int i = 1; i <= n; ++i ) cin >>d[i] >>c[i]; c[n + 1] = inf; vector< int > r(n + 1, n + 1); stack< int > st; for( int b = 0; b < 20; ++b ) { up[n + 1][b] = n + 1; sum[n + 1][b] = inf; } for( int i = n; i >= 1; --i ) { while( !st.empty() && d[st.top()] <= d[i] ) st.pop(); if( !st.empty() ) r[i] = st.top(); st.push(i); up[i][0] = r[i]; sum[i][0] = c[r[i]]; } for( int b = 1; b < 20; ++b ) for( int i = 1; i <= n; ++i ) { up[i][b] = up[up[i][b - 1]][b - 1]; sum[i][b] = sum[i][b - 1] + sum[up[i][b - 1]][b - 1]; } while( q-- ) { int u, v; cin >>u >>v; if( v <= c[u] ) { cout <<u <<nl; continue; } v -= c[u]; for( int b = 19; b >= 0; --b ) if( sum[u][b] < v ) { v -= sum[u][b]; u = up[u][b]; } cout <<up[u][0] % (n + 1) <<nl; } } signed main() { file(""); ios_base::sync_with_stdio(false); cin.tie(nullptr); // cin >>T; while( T-- ) solve(); }

컴파일 시 표준 에러 (stderr) 메시지

fountain.cpp: In function 'void file(std::string)':
fountain.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     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...