#include #include using namespace std; /* void solve(){ string n, a, b; cin >> n >> a >> b; long n_ = stol(n); long a_ = stol(a); long b_ = stol(b); if (a_ * b_ != n_) { cout << "NO" << endl; return; } const int n2 = (int)(n.length()) / 2; if ((a.length() != n2 && b.length() != n2) || (n.length() % 2) == 1){ cout << "NO" << endl; return; } map word; for (auto c: n){ word[c]++; } if (a[a.length() - 1] == '0' && b[b.length() - 1] == '0'){ cout << "NO" << endl; return; } for (auto c : a){ if (word.find(c) == word.end()){ cout << "NO" << endl; return; } auto cnt = word[c]; if (cnt == 0) { cout << "NO" << endl; return; } word[c]--; } for (auto c: b){ if (word.find(c) == word.end()){ cout << "NO" << endl; return; } auto cnt = word[c]; if (cnt == 0) { cout << "NO" << endl; return; } word[c]--; } for (auto item : word){ if (item.second != 0){ cout << "NO" << endl; return; } } cout << "YES" << endl; } int main() { int t; cin >> t; while (t--) solve(); return EXIT_SUCCESS; } #include #include using namespace std; struct line{ int position; int speed; char direction; int length; }; void solve(){ int n, m, t; cin >> n >> m >> t; vector lines(m); vector> output(n); for (auto& line: lines) { cin >> line.position >> line.speed >> line.direction >> line.length; } for (int trackNumber = 0; trackNumber < m; trackNumber++) { auto currentTrain = lines[trackNumber]; int shift = currentTrain.speed * t; int newPositionStart = currentTrain.position - shift; if (currentTrain.direction == 'R') { newPositionStart = currentTrain.position + shift; } int newPositionEnd = newPositionStart + currentTrain.length; for (int trackPosition = 0; trackPosition < n; trackPosition++){ if (newPositionStart <= trackPosition && trackPosition < newPositionEnd) { if (newPositionStart == trackPosition && currentTrain.direction == 'L') { cout << '!'; } else if (newPositionEnd-1 == trackPosition && currentTrain.direction == 'R') { cout << '!'; } else { cout << '#'; } } else { cout << '='; } } cout << '\n'; } } */ #include #include using namespace std; void solve() { int nFreq, nQueries; cin >> nFreq >> nQueries; vector frequencies(nFreq); map subArrays; for (int i = 0; i < nFreq; i++){ cin >> frequencies[i]; } for (int query = 0; query < nQueries; query++) { int start, end; cin >> start; cin >> end; start -= 1; end -= 1; bool isValid = false; for (int pos = start; pos >= 0; pos--) { if (subArrays.contains(pos)) { int currentSubArrayEnd = subArrays[pos]; int newSubArrayEnd = currentSubArrayEnd; if (currentSubArrayEnd < end) { for (int j = currentSubArrayEnd + 1; j <= end; j++) { if (frequencies[j - 1] <= frequencies[j]) { newSubArrayEnd += 1; } else { break; } } subArrays[pos] = newSubArrayEnd; if (newSubArrayEnd == end){ isValid = true; } } else { isValid = true; } break; } } if (!isValid) { int validEnd = start; for (int pos = start+1; pos <= end; pos++) { if (frequencies[pos - 1] <= frequencies[pos]) { validEnd += 1; } else { break; } } subArrays[start] = validEnd; if (validEnd == end) { isValid = true; } } if (isValid) { cout << "YES\n"; } else { cout << "NO\n"; } } }; int main() { solve(); return EXIT_SUCCESS; } // 1 2 3 2 4 -1 1