/*
Coded by thegamercoder19
GL
*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
#define FILER 0
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = pow(10, 9) + 7;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const ull INFUL = 0x3f3f3f3f3f3f3f3f;
const ll INFT = 0x3f3f3f3f;
const ll MAX = 2e5 + 1;
const ll MODD = 998244353;
const double EPS = 1e-10;
#define V vector
#define pll pair<ll, ll>
#define pull2 pair<ull,ull>
#define MS multiset
#define M map
#define Q queue
#define PQ priority_queue
#define IOF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(typ,i,a,b,c) for(typ i = a; i < b; i += c)
#define FORR(typ,i,a,b,c) for(typ i = a; i > b; i -= c)
#define FORA(a,i) for(auto &i : a)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define sorta(a) sort(all(a))
#define sortd(a) sort(all(a), greater<ll>())
#define setp(x) setprecision(x)<<fixed
#define RET return
#define log(a,b) log(b)/log(a)
#define WH(s) while(s)
#define WHI(t) WH(t--)
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YESNO(s) cout << (s ? "YES" : "NO") << endl;
#define YesNo(s) cout<<(s?"Yes":"No")<<endl;
#define TYP 0
using namespace std;
ll n, res, x;
map<ll, set<ll>> m;
V<V<ll>> g;
V<bool> used;
void dfs(ll u)
{
used[u] = 1;
FORA(g[u], v)if (!used[v])dfs(v);
}
void solve()
{
cin >> n;
used.resize(n + 1);
g.resize(n + 1);
FOR(ll, i, 1, n + 1, 1)cin >> x, m[x].insert(i);
FORA(m, mi)
FORA(mi.second, i)
{
auto j = m[mi.first - 1].upper_bound(i);
if (j != m[mi.first - 1].end()) g[i].emplace_back(*j), m[mi.first-1].erase(j);
}
FOR(ll,i,1,n+1,1)
if (!used[i])
{
dfs(i);
res++;
}
cout << res << endl;
}
void init()
{
if (FILER)
{
freopen("mootube.in", "r", stdin);
freopen("mootube.out", "w", stdout);
}
// freopen("out","w",stdout);
}
void handle()
{
init();
ll t = 1;
if (TYP)cin >> t;
//getline(cin, s);
WHI(t)solve();
}
int main()
{
IOF
handle();
RET 0;
}
Compilation message
baloni.cpp: In function 'void init()':
baloni.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | freopen("mootube.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
baloni.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | freopen("mootube.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
724 KB |
Output is correct |
5 |
Correct |
1046 ms |
56392 KB |
Output is correct |
6 |
Correct |
1126 ms |
63332 KB |
Output is correct |
7 |
Correct |
863 ms |
52164 KB |
Output is correct |
8 |
Correct |
893 ms |
51496 KB |
Output is correct |
9 |
Correct |
1002 ms |
54500 KB |
Output is correct |
10 |
Correct |
936 ms |
56396 KB |
Output is correct |