Submission #1123787

#TimeUsernameProblemLanguageResultExecution timeMemory
1123787huyngodzzPilot (NOI19_pilot)C++20
40 / 100
36 ms5568 KiB
///huynhocute123/// #include<bits/stdc++.h> using namespace std; #define S second #define F first #define pii pair<int,int> #define piii pair<int,pair<int,int>> #define pb push_back #define FOR(i, a, b) for(int i = a; i <= b; ++i) #define REP(i, a, b) for(int i = b; i >= a; --i) #define ALL(v) v.begin(),v.end() #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin); #define out(name) if(fopen(name, "w")) freopen(name, "w", stdout); //random_device rd; //mt19937 rng(rd()); //#pragma GCC optimize ("O3") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("popcnt") //#define int long long const int maxN = 1e6 +9 ; const int mod = 1e9 + 7; const int base = 2309; const int MAX = 1e9+9; const double pi = 3.14159265358979323846; const double rad = 3.14159265358979323846 /180; bool minimize(int &u, int v){ if(v < u){ u = v; return 1; } return 0; } bool maximize(int &u, int v){ if(v > u){ u = v; return 1; } return 0; } bool maximizell(long long &u, long long v){ if(v > u){ u = v; return 1; } return 0; } bool minimizell(long long &u, long long v){ if(v < u){ u = v; return 1; } return 0; } inline int fastPow(int a, int n){ if(n == 0) return 1; int t = fastPow(a, n >> 1); t = 1ll * t * t % mod; if(n & 1) t = 1ll * t * a % mod; return t; } int n , m; long long ans[maxN] , a[maxN]; priority_queue<pii ,vector<pii> ,greater<pii> >pq; int root[maxN] , sz[maxN], isActivated[maxN]; pii querries[maxN]; long long res; int Find(int u ){ return u== root[u] ? u : root[u]= Find(root[u]); } void Merge(int u ,int v){ u = Find(u); v =Find(v); if(u == v)return; // cout << u << " " << v << '\n'; res -= (sz[v] * (sz[v]+1))/2; res -= (sz[u] * (sz[u]+1))/2; root[v] = u; sz[u] += sz[v]; res += (sz[u] * (sz[u]+1))/2; } inline void solve(){ cin >>n >> m ; FOR(i, 1, n){ cin >> a[i]; pq.push({a[i] , i}); } FOR(i,1 , m){ cin >> querries[i].F; querries[i].S = i; } sort(querries +1, querries +1 + m); FOR(i, 1, n){ root[i] = i; sz[i]= 1; } // cout << pq.top().F; FOR(i, 1, m){ // cout << querries[i].F << '\n'; while(pq.size()){ int val = pq.top().F, id = pq.top().S; if(val > querries[i].F)break; // cout << val << " "; // cout <<id << " "; pq.pop(); isActivated[id] =1; res++; if(id >=2 && isActivated[id-1] ==1)Merge(id , id -1); if(id <= n -1 && isActivated[id +1] == 1)Merge(id , id +1); } // FOR(j , 1, n)cout << Find(i) << " " ; // cout << '\n'; ans[querries[i].S] = res; } // ans[1] = 1e6 *1e6 /2; FOR(i, 1, m)cout << ans[i] << '\n'; // cout << pq.top().F ; // for(auto [x, id] : arr)cout << x << " "; } signed main(){ // freopen("name.inp","r",stdin); // freopen("name.out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(0); inp("task.inp"); int tc = 1; // cin >> tc; while( tc-- )solve(); cerr << '\n' << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s\n" ; }

Compilation message (stderr)

pilot.cpp: In function 'int main()':
pilot.cpp:12:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~
pilot.cpp:127:5: note: in expansion of macro 'inp'
  127 |     inp("task.inp");
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...