Cod sursa(job #3231583)
Utilizator | Data | 27 mai 2024 11:40:03 | |
---|---|---|---|
Problema | Stramosi | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.27 kb |
#include<fstream>
int n,m,v[250001],i,x,y,k;std::ifstream f("stramosi.in");std::ofstream g("stramosi.out");int main(){f>>n>>m;for(i=1;i<=n;++i){f>>v[i];k+=(v[i]==i-1);}if(k==n)while(m--){f>>x>>y;g<<((x>=y)?(x - y):0)<<'\n';}else while(m--){f>>x>>y;while(y--&&x)x=v[x];g<<x<<'\n';}}