正文
增加 10 行删除 10 行
101 行未改动全部展开10210310410510610710810911013 行未改动12412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816921 行未改动101 行未改动全部展开if(op > 0) {while(op > 0 && s != 1) {auto& c_chain = down_chains[down_mp[s].first];int steps = min(op, down_mp[s].second);if(steps > 0) {s = c_chain[down_mp[s].second - steps];op -= steps;} else {13 行未改动#include<bits/stdc++.h>using namespace std;int parent[100005];int son[100005];pair<int,int> down_mp[100005];int n,q;vector<int> down_chains[100005];int chain_count = 0;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);cin >> n >> q;parent[1] = 0;for(int i = 0; i <= n+1; i++) son[i] = INT_MAX;for(int i = 2; i <= n; i++) {cin >> parent[i];if(i < son[parent[i]]) son[parent[i]] = i;}for(int i = 1; i <= n; i++) {if(down_mp[i].first == 0 && down_mp[i].second == 0) {int s = chain_count++;int idx = 0;for(int node = i; node != INT_MAX; node = son[node]) {down_chains[s].push_back(node);down_mp[node] = {s, idx++};}}}while(q--) {int s, k, op;cin >> s >> k;while(k--) {cin >> op;if(op > 0) {while(op > 0 && s != 1) {auto& c_chain = down_chains[down_mp[s].first];int steps = min(op, down_mp[s].second);if(steps > 0) {s = c_chain[down_mp[s].second - steps];op -= steps;} else {21 行未改动101 行未改动全部展开10210310410510610710810911013 行未改动12412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816921 行未改动101 行未改动全部展开if(op > 0) {while(op > 0 && s != 1) {auto& c_chain = down_chains[down_mp[s].first];int steps = min(op, down_mp[s].second);if(steps > 0) {s = c_chain[down_mp[s].second - steps];op -= steps;} else {13 行未改动#include<bits/stdc++.h>using namespace std;int parent[100005];int son[100005];pair<int,int> down_mp[100005];int n,q;vector<int> down_chains[100005];int chain_count = 0;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);cin >> n >> q;parent[1] = 0;for(int i = 0; i <= n+1; i++) son[i] = INT_MAX;for(int i = 2; i <= n; i++) {cin >> parent[i];if(i < son[parent[i]]) son[parent[i]] = i;}for(int i = 1; i <= n; i++) {if(down_mp[i].first == 0 && down_mp[i].second == 0) {int s = chain_count++;int idx = 0;for(int node = i; node != INT_MAX; node = son[node]) {down_chains[s].push_back(node);down_mp[node] = {s, idx++};}}}while(q--) {int s, k, op;cin >> s >> k;while(k--) {cin >> op;if(op > 0) {while(op > 0 && s != 1) {auto& c_chain = down_chains[down_mp[s].first];int steps = min(op, down_mp[s].second);if(steps > 0) {s = c_chain[down_mp[s].second - steps];op -= steps;} else {21 行未改动