QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#691383 | #7660. Investigating Frog Behaviour on Lily Pad Patterns | ptit_noodles | WA | 0ms | 3848kb | C++23 | 2.3kb | 2024-10-31 11:15:11 | 2024-10-31 11:15:14 |
Judging History
answer
#ifdef DS
#include "debug.h"
#else
#include<bits/stdc++.h>
#define deb(...)
#endif
using namespace std;
#define FOR(i,a,b) for (int i=a;i<=b;i++)
#define FOD(i,a,b) for (int i=a;i>=b;i--)
#define ALL(x) x.begin(),x.end()
#define NALL(x) x.begin()+1,x.end()
#define TIME "Time elapsed : "<<(double)clock()/1000<<" s"
#define int long long
#define vi vector<int>
#define pii pair<int,int>
const int MOD=1e9+7,INF=4e18;
#define maxn
struct Node{
int val;
Node()
{
// init val for the empty Node
val = 0;
}
};
Node makeNode(int _val)
{
Node ans;
// assign the value to Node
ans.val = _val;
return ans;
}
Node Merge(Node l,Node r)
{
Node ans;
// combine two Node
ans.val = l.val + r.val;
return ans;
}
struct Segment_Tree{
vector<Node> st;
Segment_Tree (int _sz)
{
st.resize(_sz << 2);
}
void update(int id,int l,int r,int pos,int val)
{
if (l > pos || r < pos) return;
if (l == r)
return st[id] = makeNode(val), void(); // base Node
int m = l+r >> 1;
update(id << 1,l,m,pos,val);
update(id << 1 | 1,m+1,r,pos,val);
st[id] = Merge(st[id << 1], st[id << 1 | 1]);
}
Node get(int id,int l,int r,int u,int v)
{
if (r < u || l > v) return Node();
if (l >= u && r <= v) return st[id];
int m = l+r >> 1;
return Merge(get(id << 1,l,m,u,v), get(id << 1 | 1,m+1,r,u,v));
}
};
signed main()
{
#ifndef ONLINE_JUDGE
freopen("thu.inp","r",stdin);
#endif
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n; cin>>n;
vi a(n+1);
int x_max = 0;
FOR(i,1,n)
{
cin>>a[i];
x_max = max(x_max,a[i]);
}
int N = x_max + n + 5;
Segment_Tree st(N);
FOR(i,1,n)
{
st.update(1,1,N,a[i],1);
}
int q; cin>>q;
while (q--)
{
int x; cin>>x;
int l = x+1, r = N;
int ans = -1;
while (l <= r)
{
int m = l+r >> 1;
if (st.get(1,1,N,x+1,m).val < m-x)
{
ans = m;
r = m-1;
}
else l = m+1;
}
cout<<ans<<'\n';
st.update(1,1,N,x,0);
st.update(1,1,N,ans,1);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
5 1 2 3 5 7 3 1 2 4
output:
4 6 8
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
5 1 2 3 5 7 4 1 1 1 1
output:
4 6 8 9
result:
ok 4 lines
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3592kb
input:
5 1 2 3 4 5 20 1 4 4 3 5 3 3 5 2 2 5 4 1 4 2 3 1 5 3 3
output:
6 7 8 4 9 5 10 11 3 5 12 5 2 13 4 14 2 15 5 -1
result:
wrong answer 5th lines differ - expected: '7', found: '9'