#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define a first
#define b second
#define pb push_back
#define endl '\n'
int n,m,aa;
int it[100001];
int tt[100001];
int tree[4*110001];
int tree2[4*110001];
int lazy[4*110001];
void push(int no,int l,int r){
tree[no]+=lazy[no];
tree2[no]+=lazy[no];
if(l<r){
lazy[no*2+1]+=lazy[no];
lazy[no*2+2]+=lazy[no];
}
lazy[no]=0;
}
void update(int no,int l,int r,int aa,int bb,int x){
push(no,l,r);
if(r<aa or l>bb or aa>bb){
return ;
}
if(aa<=l and r<=bb){
lazy[no]+=x;
push(no,l,r);
}
else{
int mid=(l+r)/2;
update(no*2+1,l,mid,aa,bb,x);
update(no*2+2,mid+1,r,aa,bb,x);
tree[no]=min(tree[no*2+1],tree[no*2+2]);
tree2[no]=max(tree2[no*2+1],tree2[no*2+2]);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m>>aa;
for(int i=0;i<n;i++){
char s;
cin>>s;
if(s=='+'){
it[i]=1;
}
else{
it[i]=-1;
}
cin>>tt[i+1];
}
vector<pair<int,int>> ss;
for(int i=1;i<n;i++){
//ss.pb(tt[i+1]);
ss.pb({tt[i+1]-tt[i]-1,i});
//i wil be active after this
//ss[ss.size()-1]-=tt[i];
//ss[ss.size()-1]-=1;
}
sort(ss.begin(),ss.end());
ss.pb({ss.back().a+1,-1});
int su=0;
pair<int,int> ans;
for(int i=0;i<ss.size();i++){
pair<int,int> cur={aa,aa};
int ok=0;
if(i>0){
if(ss[i-1].a<ss[i].a){
ok=1;
int ind=i-1;
while(ind>=0){
if(ss[ind].a==ss[i-1].a){
su+=it[ss[ind].b];
update(0,0,n,ss[ind].b+1,n,it[ss[ind].b]);
ind--;
}
else{
break;
}
}
}
}
else{
ok=1;
}
if(ok==1){
int x=tree[0];
int l=su-tree[0];
int r=m+(su-tree2[0]);
if(r>=aa and aa>=l){
if(i+1==ss.size()){
cout<<"infinity"<<endl;
return 0;
}
ans={ss[i].a,r};
}
}
}
//cout<<ans.a<<" "<<ans.b<<endl;
pair<int,int> cur={aa,aa};
for(int j=n-1;j>=1;j--){
if(tt[j+1]-tt[j]>ans.a){
continue;
}
if(it[j]==-1){
cur.b+=1;
cur.b=min(cur.b,m);
cur.a+=1;
if(cur.a==1){
cur.a=0;
}
}
else{
cur.a=max(0,cur.a-1);
cur.b-=1;
if(cur.b==m-1){
cur.b=m;
}
}
}
cout<<ans.a<<" "<<cur.b<<endl;
return 0;
}
Compilation message
mp3player.cpp: In function 'int main()':
mp3player.cpp:74:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int i=0;i<ss.size();i++){
| ~^~~~~~~~~~
mp3player.cpp:101:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | if(i+1==ss.size()){
| ~~~^~~~~~~~~~~
mp3player.cpp:97:8: warning: unused variable 'x' [-Wunused-variable]
97 | int x=tree[0];
| ^
mp3player.cpp:75:17: warning: variable 'cur' set but not used [-Wunused-but-set-variable]
75 | pair<int,int> cur={aa,aa};
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
468 KB |
Output is correct |
2 |
Correct |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
1624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
1680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
2720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
5064 KB |
Output is correct |
2 |
Correct |
74 ms |
4996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
5188 KB |
Output is correct |
2 |
Correct |
61 ms |
5116 KB |
Output is correct |