Hello,
I am trying to solve https://cses.fi/problemset/task/1163, but i am getting TLE on test cases 8 to 12 .
Can somebody explain? A lot of people solved that problem, I think I am missing something. Thanks.
# | User | Rating |
---|---|---|
1 | tourist | 3880 |
2 | jiangly | 3669 |
3 | ecnerwala | 3654 |
4 | Benq | 3627 |
5 | orzdevinwang | 3612 |
6 | Geothermal | 3569 |
6 | cnnfls_csy | 3569 |
8 | jqdai0815 | 3532 |
9 | Radewoosh | 3522 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | awoo | 161 |
2 | maomao90 | 160 |
3 | adamant | 156 |
4 | maroonrk | 153 |
5 | -is-this-fft- | 148 |
5 | atcoder_official | 148 |
5 | SecondThread | 148 |
8 | Petr | 147 |
9 | nor | 144 |
9 | TheScrasse | 144 |
Hello,
I am trying to solve https://cses.fi/problemset/task/1163, but i am getting TLE on test cases 8 to 12 .
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n,x;
cin>>x>>n;
multiset<long long> mul;
vector<long long> p;
p.push_back(0);
p.push_back(x);
vector<long long> q(n+1),ans(n+1);
for(long long i=0;i<n;i++)
{
long long val;
cin>>val;
p.push_back(val);
q[i+1]=val;
}
sort(p.begin(),p.end());
map<long long,long long> fwd,bk;
long long sz=p.size();
fwd[0]=p[1];
bk[x]=p[sz-2];
for(long long i=1;i<=(sz-2);i++)
{
fwd[p[i]]=p[i+1];
bk[p[i]]=p[i-1];
}
for(long long i=1;i<=(sz-1);i++)
{
mul.insert(p[i]-p[i-1]);
}
for(long long i=n;i>=1;i--)
{
ans[i]=*mul.rbegin();
long long val=q[i];
mul.erase(fwd[val]-val);
mul.erase(val-bk[val]);
mul.insert(fwd[val]-bk[val]);
long long a=fwd[val];
long long b=bk[val];
bk[a]=b;
fwd[b]=a;
}
for(long long i=1;i<=n;i++)
{
cout<<ans[i]<<" ";
}
cout<<'\n';
return 0;
}
Can somebody explain? A lot of people solved that problem, I think I am missing something. Thanks.
Recently I have found that the submission verdict of a problem does not gets updated in real time. for example it gets stuck on "Running on test case 1" and it only changes once i refresh the webpage. Is it only happening with me or some other users are also facing this problem.
Name |
---|