Hello,
I am trying to solve https://cses.fi/problemset/task/1163, but i am getting TLE on test cases 8 to 12 .
CODE
Can somebody explain? A lot of people solved that problem, I think I am missing something. Thanks.
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
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 |
---|