Submission #407302

# Submission time Handle Problem Language Result Execution time Memory
407302 2021-05-18T17:33:31 Z victoriad Fountain (eJOI20_fountain) C++14
30 / 100
421 ms 524292 KB
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <iomanip>
#include <stack>
#include <fstream>
using namespace std;
 
int search(int l,vector<pair<int,int> >&p){
	int lo=0,hi=p.size(),mid,r=-1;
	if(l>p.back().second)return 0;
	while(lo<=hi){
		mid=lo+(hi-lo)/2;
		if(p[mid].second>=l){
			r=mid;
			hi=mid-1;
		}
		else{
			lo=mid+1;
		}
	}
	
	if(r==-1)return 0;
	else return p[r].first+1;
}
int main(){
  ios::sync_with_stdio(false);
   cin.tie(NULL);
    int n,q;
    cin>>n>>q;
	int l,r;
    vector<long long int>v(n);
    vector<long long int>d(n);
    for(int i=0;i<n;i++){
      cin>>d[i]>>v[i];
    }
	vector<int>con(n);
	vector<int>grupo(n,-1);
	int cc=0;
	for(int i=0;i<n;i++){
		bool b=false;
		for(int k=i;k<n;k++){
			if(d[i]<d[k]){
				con[i]=k;
				b=true;
				break;
			}
		}
		if(!b)con[i]=-1;
	}
	vector<vector<pair<int,int> > >ps(n);
	for(int i=n-1;i>=0;i--){
		vector<pair<int,int> >a;
		if(con[i]==-1)
		a.push_back(make_pair(i,v[i]));
		else{
			a.resize(ps[con[i]].size()+1);
			a[0]=(make_pair(i,v[i]));
			for(int k=0;k<ps[con[i]].size();k++){
				a[k+1]=make_pair(ps[con[i]][k].first,ps[con[i]][k].second +v[i]);
			}
			
		}
		ps[i]=a;
	}
    for(int i=0;i<q;i++){
      cin>>r>>l;
      r--;
      if(l<=v[r])cout<<r+1<<"\n";
	  else{
		  cout<<search(l,ps[r])<<"\n";
	  }
    }
  return 0;
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:64:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |    for(int k=0;k<ps[con[i]].size();k++){
      |                ~^~~~~~~~~~~~~~~~~~
fountain.cpp:44:6: warning: unused variable 'cc' [-Wunused-variable]
   44 |  int cc=0;
      |      ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 8 ms 6184 KB Output is correct
6 Correct 3 ms 1740 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 421 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 8 ms 6184 KB Output is correct
6 Correct 3 ms 1740 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Runtime error 421 ms 524292 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -