#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cctype>
#include <string>
#include <cassert>
#include <set>
#include <bitset>
#include <unordered_set>
using ll = int64_t;
#define pb push_back
#define all(a) a.begin(),a.end()
#define ppi pair<pair<int,int>,int>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//#define int int64_t
// xcode cant include bits/stdc++.h
using namespace std;
//ifstream fin ("sleepy.in");
//ofstream fout ("sleepy.out");
/* /\_/\
* (= ._.)
* / > \>
*/
// encouraging cat
const int INF = 10000000000000000;
const int mod = 1000000007;
int32_t main() {
fast
int n,q;
cin >> n >> q;
vector<pair<int,int>> a(n,{-1,-1});
for (int i = 0;i < n;i++)
{
cin >> a[i].first >> a[i].second;//diameter,volume
}
vector<vector<pair<int,int>>> query;//query number,v
query.resize(n);
vector<int> res(q,0);
for (int i = 0;i < q;i++)
{
int r,v;
cin >> r >> v;
r--;
query[r].pb({i,v});
}
stack<ppi> st;//quantity,radius,query
for (int i = 0;i < n;i++)
{
stack<ppi> curr;
while (!st.empty() && a[i].first > st.top().first.second)
{
int q = st.top().first.first;
int r = st.top().first.second;
int qu = st.top().second;
if (q - a[i].second > 0)
{
curr.push({{q - a[i].second,a[i].first},qu});
}
else
{
res[qu] = i + 1;
}
st.pop();
}
while (!curr.empty())
{
st.push(curr.top());
curr.pop();
}
for (int j = 0;j < query[i].size();j++)
{
if (a[i].second >= query[i][j].second)
{
res[query[i][j].first] = i + 1;
}
else
{
st.push({{query[i][j].second - a[i].second,a[i].first},query[i][j].first});
}
}
}
for (int i = 0;i < q;i++)
{
cout << res[i] << '\n';
}
return 0;
}
Compilation message
fountain.cpp:32:9: warning: "/*" within comment [-Wcomment]
32 | /* /\_/\
|
fountain.cpp:37:17: warning: overflow in conversion from 'long int' to 'int' changes value from '10000000000000000' to '1874919424' [-Woverflow]
37 | const int INF = 10000000000000000;
| ^~~~~~~~~~~~~~~~~
fountain.cpp: In function 'int32_t main()':
fountain.cpp:65:17: warning: unused variable 'r' [-Wunused-variable]
65 | int r = st.top().first.second;
| ^
fountain.cpp:82:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for (int j = 0;j < query[i].size();j++)
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1539 ms |
6212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Execution timed out |
1539 ms |
6212 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |