版本比较
题解:CF1902D Robot Queries
正文
增加 7 行删除 10 行
1234534 行未改动40414243444546474810 行未改动59606162636465666768697071727374753 行未改动79808182838485866 行未改动[**题目传送门**](https://www.luogu.com.cn/problem/CF1902D)[**更好的阅读体验**](https://www.cnblogs.com/Charllote/p/19170089)## 前置知识——向量的加减34 行未改动int n, q, x, y, l, r;PII a[N];map<PII, vector<int>> mp;PII add(PII x, PII y) {return {x.first + y.first, x.second + y.second};}PII re(PII x) {10 行未改动cin >> n >> q;mp[{0, 0}].push_back(0);for (int i = 1; i <= n; i ++ ) {char ch; cin >> ch;if (ch == 'U') {a[i] = {a[i - 1].first, a[i - 1].second + 1};} else if (ch == 'D') {a[i] = {a[i - 1].first, a[i - 1].second - 1};} else if (ch == 'L') {a[i] = {a[i - 1].first - 1, a[i - 1].second};} else {a[i] = {a[i - 1].first + 1, a[i - 1].second};}mp[a[i]].push_back(i);}while (q -- ) {3 行未改动if (mp.count(p) && (check(mp[p], 0, l - 1) || check(mp[p], r, n))) {cout << "YES\n";continue;}PII finded = add(add(re(p), a[l - 1]), a[r]);if (mp.count(finded) && check(mp[finded], l, r - 1)) {cout << "YES\n";continue;6 行未改动12345634 行未改动41424344454647484910 行未改动6061626364656667686970713 行未改动7576777879808182836 行未改动[**题目传送门**](https://www.luogu.com.cn/problem/CF1902D)[**更好的阅读体验**](https://www.cnblogs.com/Charllote/p/19170089)## 前置知识——向量的加减34 行未改动int n, q, x, y, l, r;PII a[N];map<PII, vector<int>> mp;PII add(PII x, PII y) {return {x.first + y.first, x.second + y.second};}PII re(PII x) {10 行未改动cin >> n >> q;mp[{0, 0}].push_back(0);for (int i = 1; i <= n; i ++ ) {char ch; cin >> ch;if (ch =='U') { a[i] = add(a[i - 1], {0, 1}); }else if (ch =='D') {a[i] = add(a[i - 1], {0, -1});}else if (ch =='L') {a[i] = add(a[i - 1], {-1, 0});}else if (ch =='R') {a[i] = add(a[i - 1], {1, 0});}mp[a[i]].push_back(i);}while (q -- ) {3 行未改动if (mp.count(p) && (check(mp[p], 0, l - 1) || check(mp[p], r, n))) {cout << "YES\n";continue;}PII finded = add(add(re(p), a[l - 1]), a[r]);if (mp.count(finded) && check(mp[finded], l, r - 1)) {cout << "YES\n";continue;6 行未改动