Skip to content

Commit 005d35d

Browse files
committed
Adding submissions
1 parent 4cf29cd commit 005d35d

File tree

3 files changed

+99
-1
lines changed
  • codeforces

3 files changed

+99
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// http://codeforces.com/contest/220/problem/A
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
#define __ ios_base::sync_with_stdio(0); cin.tie(0);
6+
#define endl '\n'
7+
#define foreach(it, x) for (__typeof (x).begin() it = (x).begin(); it != (x).end(); ++it)
8+
#define all(x) x.begin(),x.end()
9+
#define D(x) cout << #x " = " << (x) << endl;
10+
11+
template <class T> string toStr(const T &x)
12+
{ stringstream s; s << x; return s.str(); }
13+
14+
template <class T> int toInt(const T &x)
15+
{ stringstream s; s << x; int r; s >> r; return r; }
16+
17+
int dx[8] = {-1,-1,-1,0,1,1, 1, 0};
18+
int dy[8] = {-1, 0, 1,1,1,0,-1,-1};
19+
20+
int main() {
21+
int n;
22+
cin >> n;
23+
24+
vector<int> v(n), vv;
25+
for (int i = 0; i < n; ++i) cin >> v[i];
26+
27+
vv = v;
28+
sort(all(vv));
29+
30+
int diffs = 0;
31+
for (int i = 0; i < n; ++i) if (v[i] != vv[i]) diffs ++;
32+
33+
if (diffs <= 2) cout << "YES";
34+
else cout << "NO";
35+
36+
return 0;
37+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// http://codeforces.com/contest/242/problem/B
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
#define __ ios_base::sync_with_stdio(0); cin.tie(0);
6+
#define endl '\n'
7+
#define foreach(it, x) for (__typeof (x).begin() it = (x).begin(); it != (x).end(); ++it)
8+
#define all(x) x.begin(),x.end()
9+
#define D(x) cout << #x " = " << (x) << endl;
10+
11+
template <class T> string toStr(const T &x)
12+
{ stringstream s; s << x; return s.str(); }
13+
14+
template <class T> int toInt(const T &x)
15+
{ stringstream s; s << x; int r; s >> r; return r; }
16+
17+
int dx[8] = {-1,-1,-1,0,1,1, 1, 0};
18+
int dy[8] = {-1, 0, 1,1,1,0,-1,-1};
19+
20+
struct seg {
21+
int size;
22+
int left;
23+
int rigth;
24+
int pos;
25+
};
26+
27+
bool comp(seg i, seg j) {
28+
return i.size > j.size;
29+
}
30+
31+
int main() {
32+
int n;
33+
cin >> n;
34+
35+
vector<seg> v(n);
36+
for (int i = 0; i < n; ++i) {
37+
int l, r;
38+
cin >> l >> r;
39+
seg sg;
40+
sg.left = l;
41+
sg.rigth = r;
42+
sg.size = (r - l) + 1;
43+
sg.pos = i + 1;
44+
45+
v[i] = sg;
46+
}
47+
48+
sort(all(v), comp);
49+
50+
for (int i = 1; i < n; ++i) {
51+
if (v[i].left < v[0].left || v[i].rigth < v[0].left || v[i].rigth > v[0].rigth || v[i].left > v[0].rigth) {
52+
cout << -1;
53+
return 0;
54+
}
55+
}
56+
57+
cout << v[0].pos;
58+
return 0;
59+
}

codeforces/data.db

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,4 +647,6 @@
647647
12998226
648648
13001578
649649
13002330
650-
13002434
650+
13002434
651+
13002660
652+
13002662

0 commit comments

Comments
 (0)