#include<bits/stdc++.h>
using namespace std;
int dizi[1000007];
// vector<int> r[1000007];
list<int> r[1000007];
bool visit[1000007];
int main()
{
// cout << "yarrr";
int n;
cin >> n;
// cout << "ar";
// memset(r,-1,sizeof(r));
// memset(r,-1,sizeof(r));
for(int i=0;i<n;i++)
{
cin >> dizi[i];
}
// cout << "adasd";
r[dizi[n-1]].push_back(n-1);
for(int i=n-2;i>=0;i--)
{
// cout << i << " ";
if(r[dizi[i]-1].size()>0)
{
for(auto x:r[dizi[i]-1])
r[i].push_front(x);
// r[i].push_back(r[dizi[i]-1]);
}
r[dizi[i]].push_back(i);
}
// cout << endl;
// for(int i=0;i<n;i++)
// {
// for(auto x:r[i])
// cout << x << " ";
// cout << endl;
// // cout << r[i] << " ";
// }
// free(r);
// ~r;
// delete[] r;
long long int sayac=0;
for(int i=0;i<n;i++)
{
if(visit[i]==1)
continue;
sayac++;
while(!r[i].empty()&&visit[r[i].front()]==1)
r[i].pop_front();
int ptr=i;
while(!r[ptr].empty() && visit[r[ptr].front()]!=1)
{
visit[ptr]=1;
ptr=r[ptr].front();
// cout << ptr << " ";
}
visit[ptr]=1;
// cout << endl;
}
// cout << visit[7] << " ";
cout << sayac;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
23928 KB |
Output isn't correct |
2 |
Incorrect |
27 ms |
24056 KB |
Output isn't correct |
3 |
Incorrect |
29 ms |
24312 KB |
Output isn't correct |
4 |
Incorrect |
29 ms |
24440 KB |
Output isn't correct |
5 |
Runtime error |
722 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
6 |
Runtime error |
735 ms |
131072 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
7 |
Runtime error |
755 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Runtime error |
578 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Runtime error |
714 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Runtime error |
680 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |