#include #include using namespace std; void ParseQuery(int QueryId, int x); void Connect(int x); void Separate(int x); void Remodel(int x); void Attr(int x); std::vector CoolVals; std::vector ConnectInfo; int main() { int CarQty, QueryQty; scanf("%d%d", &CarQty, &QueryQty); for (int i = 0; i < CarQty; i++) { int Val; scanf("%d", &Val); CoolVals.push_back(Val); ConnectInfo.push_back(false); } while (QueryQty-->0) { int QueryId, x; scanf("%d%d", &QueryId, &x); ParseQuery(QueryId, x-1); } return 0; } void ParseQuery(int QueryId, int x) { switch (QueryId) { case 1: Connect(x); break; case 2: Separate(x); break; case 3: Remodel(x); break; case 4: Attr(x); break; default: break; } } void Connect(int x) { ConnectInfo[x] = true; } void Separate(int x) { ConnectInfo[x] = false; } void Remodel(int x) { CoolVals[x]++; } void Attr(int x) { int CarPos = x; while (CarPos != 0 && ConnectInfo[CarPos-1] == true) { CarPos--; } int Attr = 0; do { Attr += CoolVals[CarPos]; } while (ConnectInfo[CarPos++] == true); printf("%d\n", Attr); }