Cod sursa(job #3155980)
Utilizator | Data | 10 octombrie 2023 13:09:45 | |
---|---|---|---|
Problema | Stramosi | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.4 kb |
#include<fstream>
using namespace std;
ifstream F("stramosi.in");
ofstream G("stramosi.out");
int n,m,i,x,y,v[250001],j;
int main()
{
for(F>>n>>m,i=1;i<=n;++i) {
F>>v[i];
if(v[i]==i-1)
++j;
}
if(j==n)
while(m--)
F>>x>>y,G<<(x>=y?(x-y):0)<<'\n';
else
while(m--) {
for(F>>x>>y;x&&y;--y,x=v[x]);
G<<x<<'\n';
}
return 0;
}