Submission #704537

# Submission time Handle Problem Language Result Execution time Memory
704537 2023-03-02T09:10:35 Z thrasherr_1 Fountain (eJOI20_fountain) C++17
0 / 100
1500 ms 19532 KB
#include <bits/stdc++.h>
using namespace std ;

#define ff first
#define ss second
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ones(x) __builtin_popcount(x)
#define remove(v)  v.erase(unique(all(v)), v.end())
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)

#ifdef local
#include "C:\debug.h"
#else
#define dbg(x...) 42
#endif

#define int ll

const int N = 1e5 + 2 ;

int n , q , d[N] , c[N] , pr[N] , ans[N] ;
set<pair<int,int>> e[N] ;

void solve(){
    cin >> n >> q ;
    rep(i , 1 , n) {
        cin >> d[i] >> c[i] ;
    }
    stack<pair<int,int>> s ;
    s.push({LLONG_MAX , n + 2}) ;
    per(i , n , 1){
        while(sz(s) && s.top().first <= d[i]) s.pop() ;
        pr[i] = s.top().second ;
        s.push({d[i] , i}) ;
    }
    rep(i , 1 , q) {
        int f , l ; cin >> f >> l ;
        e[f].insert({l , i}) ;
    }
    rep(i , 1 , n) {
        if(sz(e[i])) {
            dbg(e[i] , i) ;
            int cur = i ;
            int sum = c[i] ;
            while(cur <= n) {
                dbg(cur) ;
                if(sz(e[i])) {
                    auto [l , id] = *e[i].begin() ;
                    if(l <= sum) {
                        ans[id] = cur ;
                        e[i].erase(e[i].begin()) ;
                    }
                }
                cur = pr[cur] ;
                if(cur <= n) sum += c[cur] ;
            }
        }
    }
    rep(i , 1 , q) {
        cout << ans[i] << "\n" ;
    }
}

signed main () {
	ios::sync_with_stdio(false) ;
	cin.tie(0) ;
	int test = 1 ;
	// cin >> test ; 
	for(int i = 1 ; i <= test ; i++) {
		solve() ;
	}
}

Compilation message

fountain.cpp: In function 'void solve()':
fountain.cpp:20:19: warning: statement has no effect [-Wunused-value]
   20 | #define dbg(x...) 42
      |                   ^~
fountain.cpp:48:13: note: in expansion of macro 'dbg'
   48 |             dbg(e[i] , i) ;
      |             ^~~
fountain.cpp:20:19: warning: statement has no effect [-Wunused-value]
   20 | #define dbg(x...) 42
      |                   ^~
fountain.cpp:52:17: note: in expansion of macro 'dbg'
   52 |                 dbg(cur) ;
      |                 ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1568 ms 19532 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5024 KB Output isn't correct
2 Halted 0 ms 0 KB -