14045: 【原4045】日天要读书

题目描述

author: MW 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/4045

Sample Input 1

5 5
5 4 3 2 1
1 5 3
1 3 1
2 4 3
4 4 4
2 5 3


Sample Output 1

Yes
No
Yes
Yes
No


Sample Input 2

6 5
1 4 3 2 5 6
2 4 3
1 6 2
4 5 4
1 3 3
2 6 3


Sample Output 2

Yes
No
Yes
No
Yes


样例解释

1. [1, 2, 3, 4, 5]为排序后的序列, 原来第3个元素的位置没有变化，所以答案为"Yes"
2. [3, 4, 5, 2, 1]为排序后的序列, 原来第1个元素的位置发生变化，所以答案为"No"
3. [5, 2, 3, 4, 1]为排序后的序列, 原来第3个元素的位置没有变化，所以答案为"Yes".
4. [5, 4, 3, 2, 1]为排序后的序列, 原来第4个元素的位置没有变化，所以答案为"Yes".
5. [5, 1, 2, 3, 4]为排序后的序列, 原来第3个元素的位置发生变化，所以答案为"No".

BugenZhao's solution

//
// Created by BugenZhao on 2019/3/23.
//

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

using ll=long long;

/*
int lessCount[10005][10005];
int p[10005];

int main() {
int n, m;
cin >> n >> m;
int tmp;
for (int i = 1; i <= n; ++i) {
scanf("%d", &tmp);
p[i] = tmp;
for (int j = 1; j <= n; ++j) {
lessCount[j][i] = lessCount[j][i - 1] + (j > tmp);
}
}

int l, r, x;
while (m--) {
scanf("%d%d%d", &l, &r, &x);
tmp = p[x];
if (lessCount[tmp][r] - lessCount[tmp][l] == x - l) {
printf("Yes\n");
} else {
printf("No\n");
}
}
}

*/

int main() {
int table[10005];
int n, m;
cin >> n >> m;
int tmp;
for (int i = 1; i <= n; ++i) {
scanf("%d", &table[i]);
}

int l, r, x, count;
while (m--) {
scanf("%d%d%d", &l, &r, &x);
if (x < l || x > r) {
printf("Yes\n");
continue;
}
count = 0;
tmp = table[x];
for (int i = l; i <= r; ++i) {
if (table[i] < tmp) ++count;
}
if (count == x - l) {
printf("Yes\n");
} else {
printf("No\n");
}
}
}


FineArtz's solution

/* 日天要读书 */
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> p(n + 1, 0);
for (int i = 1; i <= n; ++i)
cin >> p[i];
vector<int> q(p.begin(), p.end());
int l, r, x;
while (m--){
q = p;
cin >> l >> r >> x;
sort(q.begin() + l, q.begin() + r + 1);
auto ite = find(q.begin(), q.end(), p[x]);
if (distance(q.begin(), ite) == x) cout << "Yes\n";
else cout << "No\n";
}
return 0;
}


ligongzzz's solution

#include "iostream"
#include "cstdio"
using namespace std;

int origin[10009] = { 0 };
int num_data[10009] = { 0 };

int main() {
int n, m;
scanf("%d %d", &n, &m);

for (int i = 1; i <= n; ++i) {
scanf("%d", &origin[i]);
//num_data[i] = origin[i];
}

for (int i = 0; i < m; ++i) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
if (x<l || x>r) {
printf("Yes\n");
}
else {
int cnt = 0;
for (int j = l; j <= r; ++j) {
if (j == x)
continue;
if (origin[j] < origin[x])
++cnt;
}
if (cnt == x - l)
printf("Yes\n");
else
printf("No\n");
}
}

return 0;
}


skyzh's solution

#include <iostream>
#include <queue>
#include <cstdio>
using namespace std;

int A[10000];

int main() {
int N, T;
scanf("%d%d", &N, &T);
for (int i = 0; i < N; i++) {
scanf("%d", &A[i]);
}

int l, r, x;

priority_queue <int, vector<int>, greater<int> > q;

for (int i = 0; i < T; i++) {
scanf("%d%d%d", &l, &r, &x);
if (x < l || x > r) printf("Yes\n");
else {
for (int j = l; j <= r; j++) q.push(A[j - 1]);
int pg = A[x - 1];
int pos = x - l;
for (int j = 0; j < pos; j++) q.pop();
if (q.top() == pg) printf("Yes\n");
else printf("No\n");
while (!q.empty()) q.pop();
}
}
return 0;
}


yyong119's solution

#include <cstdio>
#define MAX_N 10010
using namespace std;
int n, m, l, r, x, cnt;
int a[MAX_N];
inline int read() {
char ch = getchar(); int res = 0, flag = 1;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') flag = -1, ch = getchar();
while (ch >= '0' && ch <= '9') res = res * 10 + ch - '0', ch = getchar();
// return res * flag;
return res;
}
int main() {
for (register int i = 1; i <= n; ++i) a[i] = read();
for (register int i = 0; i < m; ++i) {