# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
478203 |
2021-10-06T13:02:30 Z |
urosk |
Sirni (COCI17_sirni) |
C++14 |
|
3006 ms |
629252 KB |
// __builtin_popcount(x) broj bitova
// __builtin_popcountll(x) long long
#define here cerr<<"---------------------------\n"
#include "bits/stdc++.h"
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll int
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
void setIO(string inoutname)
{
freopen((inoutname+".in").c_str(),"r",stdin);
freopen((inoutname+".out").c_str(),"w",stdout);
}
#define mod 1
ll gcd(ll a, ll b)
{
if(b==0) return a;
if(a==0) return b;
if(a>=b) return gcd(a%b,b);
return gcd(a,b%a);
}
ll lcm(ll a,ll b){
return (a/gcd(a,b))*b;
}
ll add(ll a,ll b){
a+=b;
a+=mod;
if(a>=mod) a%=mod;
return a;
}
ll mul(ll a,ll b){return(a*b)%mod;}
#define maxn 100005
#define maxm 10000005
ll n;
ll a[maxn];
ll dsu[maxn];
ll b[maxm];
ll id[maxm];
ll root(ll x){
while(x!=dsu[x]){
dsu[x] = dsu[dsu[x]];
x = dsu[x];
}
return x;
}
bool get(ll x,ll y){return root(x)==root(y);}
void upd(ll x,ll y){dsu[root(y)] = root(x);}
bool bio[maxm];
vector<pll> g[maxm];
void tc(){
ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
cin >> n;
for(ll i = 1;i<=n;i++){
cin >> a[i];
b[a[i]] = a[i];
if(!id[a[i]]) id[a[i]] = i;
}
iota(dsu+1,dsu+n+1,1);
for(ll i = maxm-2;i>=1;i--){
if(b[i]) continue;
b[i] = b[i+1];
}
for(ll i = 1;i<=n;i++){
if(bio[a[i]]) continue;
bio[a[i]] = 1;
if(b[a[i]+1]){
if(2*a[i]>=maxm||b[2*a[i]]!=b[a[i]+1]){
g[b[a[i]+1]-a[i]].pb({i,id[b[a[i]+1]]});
}
}
for(ll j = 2*a[i];j<maxm&&b[j];j+=a[i]){
if(j+a[i]>=maxm||b[j+a[i]]!=b[j]){
g[b[j]-j].pb({i,id[b[j]]});
}
}
}
ll ans = 0;
for(ll j = 0;j<maxm;j++){
for(pll p : g[j]){
ll u = p.fi;
ll v = p.sc;
if(get(v,u)) continue;
upd(v,u);
ans+=j;
}
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
//setIO("lol");
int t; t = 1;
while(t--){
tc();
}
return 0;
}
Compilation message
sirni.cpp: In function 'void setIO(std::string)':
sirni.cpp:32:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((inoutname+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:33:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((inoutname+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
208 ms |
281156 KB |
Output is correct |
2 |
Correct |
259 ms |
280668 KB |
Output is correct |
3 |
Correct |
191 ms |
281668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
274404 KB |
Output is correct |
2 |
Correct |
415 ms |
276156 KB |
Output is correct |
3 |
Correct |
232 ms |
281540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
195 ms |
281644 KB |
Output is correct |
2 |
Correct |
195 ms |
277840 KB |
Output is correct |
3 |
Correct |
215 ms |
281644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
318 ms |
289500 KB |
Output is correct |
2 |
Correct |
380 ms |
315304 KB |
Output is correct |
3 |
Correct |
283 ms |
294328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
223 ms |
280900 KB |
Output is correct |
2 |
Correct |
312 ms |
301352 KB |
Output is correct |
3 |
Correct |
246 ms |
286988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
337 ms |
301140 KB |
Output is correct |
2 |
Correct |
429 ms |
329224 KB |
Output is correct |
3 |
Correct |
272 ms |
292860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
247 ms |
278760 KB |
Output is correct |
2 |
Correct |
411 ms |
326500 KB |
Output is correct |
3 |
Correct |
272 ms |
291452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
371 ms |
336216 KB |
Output is correct |
2 |
Correct |
1587 ms |
537572 KB |
Output is correct |
3 |
Correct |
369 ms |
339560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
339 ms |
335860 KB |
Output is correct |
2 |
Correct |
2762 ms |
629252 KB |
Output is correct |
3 |
Correct |
384 ms |
343576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
237 ms |
320452 KB |
Output is correct |
2 |
Correct |
3006 ms |
619464 KB |
Output is correct |
3 |
Correct |
302 ms |
294992 KB |
Output is correct |