結果

問題 No.1268 Fruit Rush 2
ユーザー chocorusk
提出日時 2020-10-25 03:20:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 1,736 bytes
コンパイル時間 1,388 ms
コンパイル使用メモリ 130,432 KB
最終ジャッジ日時 2025-01-15 15:38:11
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
typedef pair<int, int> P;
ll solve(vector<ll> v){
vector<ll> v1, v0, w0, w1;
for(auto x:v){
if(x&1) v1.push_back(x), w1.push_back(x);
else v0.push_back(x), w0.push_back(x);
}
for(int i=0; i<v0.size(); i++) v0[i]-=2*i;
for(int i=0; i<v1.size(); i++) v1[i]-=2*i;
ll ans=0;
for(int i=0; i<v0.size(); i++){
ll x=w0[i];
int t=lower_bound(w1.begin(), w1.end(), x+1)-w1.begin();
if(t==w1.size() || w1[t]>x+1) continue;
int u=upper_bound(v1.begin(), v1.end(), v1[t])-v1.begin();
ans+=u-t;
}
for(int i=0; i<v1.size(); i++){
ll x=w1[i];
int t=lower_bound(w0.begin(), w0.end(), x+1)-w0.begin();
if(t==w0.size() || w0[t]>x+1) continue;
int u=upper_bound(v0.begin(), v0.end(), v0[t])-v0.begin();
ans+=u-t;
}
return ans;
}
int main()
{
int n; cin>>n;
ll a[200020];
for(int i=0; i<n; i++){
cin>>a[i];
}
sort(a, a+n);
vector<ll> v;
v.push_back(a[0]);
ll ans=n;
for(int i=1; i<n; i++){
if(a[i]-a[i-1]>2){
ans+=solve(v);
v.clear();
}
v.push_back(a[i]);
}
ans+=solve(v);
cout<<ans<<endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0