답안 #570180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
570180 2022-05-28T20:05:11 Z thatsgonzalez Mountains (NOI20_mountains) C++14
0 / 100
2000 ms 8532 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector <char> vc;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef pair<ll,ll> pl;
typedef double dou;
typedef vector<pl> vpl;
typedef unsigned long long ull;
typedef uint64_t i64;
typedef vector <pair<int,ii>> graph;
typedef priority_queue<ii,vii,greater<ii>> priority_graph;
typedef vector<ull> vull;

#define f first 
#define s second 
#define pb push_back 
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define ts to_string
#define lb lower_bound 
#define ub upper_bound
#define yes cout<<'Y'<<'E'<<'S'<<endl
#define no cout<<'N'<<'O'<<endl
#define nd "\n"

void setIO(string name=""){ios_base::sync_with_stdio(0);cin.tie(0);if(sz(name)){freopen((name+".in").c_str(),"r",stdin);freopen((name+".out").c_str(),"w",stdout);}}
 
ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
ll mcm(ll a, ll b) {return (a * b) / gcd(a, b);}
bool prime(ll n) {for(int i=2; i<=sqrt(n); i++) if(n%i==0) return false; return true;}
struct compii{bool operator()(const ii &a, const ii &b){if(a.f==a.s)return a.s<b.s;return a.f>b.f;}};
bool comp(int a, int b) {return a>b;}
ll binpow(ll n, ll x){ll ans=1; while(x){if(x&1){ans*=n;}n*=n; x>>=1;} return ans;}

namespace operators {
template<typename T1, typename T2>istream& operator>>(istream& in, pair<T1, T2>& x){in >> x.first >> x.second;return in;}
template<typename T1, typename T2>ostream& operator<<(ostream& out, pair<T1, T2> x){out << x.first << " " << x.second;return out;}
template<typename T1>istream& operator>>(istream& in, vector<T1>& x) {for (auto& i : x) in >> i;return in;}
template<typename T1>ostream& operator<<(ostream& out, vector<T1>& x) {for (auto& i : x) out << i << " ";return out;}
template<typename T1, typename T2>ostream& operator<<(ostream& out, vector<pair <T1,T2>>& x) {for (auto& i : x) out << i.f << " "<<i.s;return out;}
template<typename T1, typename T2>istream& operator>>(istream& in, vector<pair <T1,T2>>& x) {for (auto& i : x) in >> i.f >>i.s;return in;}
}

using namespace operators;

int dx[]= {1,0,-1,0};
int dy[]= {0,1,0,-1};

const int mod=1e9+7;
const ll inf=1e18;
int n;

vl ft1,ft2;

int lsb(int x){
  return x & (-x);
}

ll query(int ind, bool who){
  ll res=0;
  while(ind){
    if(who) res+=ft1[ind];
    else res+=ft2[ind];
    ind-=lsb(ind);
  }
  return res;
}

void update(int ind, int value, bool who){
  while(ind<=n){
    if(who) ft1[ind]+=value;
    else ft2[ind]+=value;
    ind+=lsb(value);
  }
}

void solve()
{
  cin>>n;
  ft1.assign(n+1,0); ft2.assign(n+1,0);
  int a[n]; 
  vii aux(n);
  for(int i=0; i<n; i++){
    int x; cin>>x; aux[i]={x,i};
  }
  sort(all(aux)); a[aux[0].s]=1; int temp=1;
  for(int i=1; i<n; i++){
    if(aux[i].f==aux[i-1].f) a[aux[i].s]=temp;
    else temp++, a[aux[i].s]=temp;
  }
  //for(auto &x: a) cout<<x<<" "; cout<<endl; 
  int mx=0;
  for(int i=n-1; i>=0; i--){
    mx=max(mx,a[i]);
    update(a[i],1,1);
  }
  //cout<<query(mx-1,1)<<endl;
  //int top=n+99;
  update(a[0]+1,1,0);
  update(a[0]+1,-1,1);
  ll ans=0;
  for(int i=1; i<n-1; i++){
    update(a[i],-1,1);
    //cout<<query(a[i]-1,0)<<" "<<query(a[i]-1,1)<<endl;
    ans+=query(a[i]-1,0)*(query(a[i]-1,1));
    update(a[i],1,0);
  }
  cout<<ans<<endl;
}
int main ()
{
  setIO("");
  int t=1;
  //cin>>t;
  while(t-->0) solve();
  return 0;
}

Compilation message

Mountains.cpp: In function 'void setIO(std::string)':
Mountains.cpp:36:88: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 | void setIO(string name=""){ios_base::sync_with_stdio(0);cin.tie(0);if(sz(name)){freopen((name+".in").c_str(),"r",stdin);freopen((name+".out").c_str(),"w",stdout);}}
      |                                                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mountains.cpp:36:128: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 | void setIO(string name=""){ios_base::sync_with_stdio(0);cin.tie(0);if(sz(name)){freopen((name+".in").c_str(),"r",stdin);freopen((name+".out").c_str(),"w",stdout);}}
      |                                                                                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 2084 ms 8532 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2091 ms 8532 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2091 ms 8532 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2091 ms 8532 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 2084 ms 8532 KB Time limit exceeded
3 Halted 0 ms 0 KB -