제출 #1020247

#제출 시각아이디문제언어결과실행 시간메모리
1020247YassineBenYounesFish 3 (JOI24_fish3)C++17
0 / 100
276 ms48444 KiB
#include<bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef double db; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define pbds tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> using namespace __gnu_pbds; ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD) ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM) int dx[8] = {1, 0, 0, -1, 1, 1, -1, -1}; int dy[8] = {0, 1, -1, 0, 1, -1, -1, 1}; #define endl "\n" #define ss second #define ff first #define all(x) (x).begin() , (x).end() #define pb push_back #define vi vector<int> #define vii vector<pair<int,int>> #define vl vector<ll> #define vll vector<pair<ll,ll>> #define pii pair<int,int> #define pll pair<ll,ll> #define pdd pair<double,double> #define vdd vector<pdd> #define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; ////////////////////Only Clear Code////////////////////////// void usaco_problem(){ freopen("milkvisits.in", "r", stdin); freopen("milkvisits.out", "w", stdout); } void init(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // ONLINE_JUDGE } const int mx = (3e5+2)*4; const int LOG = 25; const int inf = 1e9; const ll mod = 998244353; #define int ll ll arr[mx]; ll segtree[mx], fst[mx]; ll lft[mx], rgt[mx]; void combine(int c, int a, int b){ if(arr[rgt[a]] <= fst[b]){ segtree[c] = segtree[a] + segtree[b]; fst[c] = fst[a]; return; } ll steps = arr[rgt[a]] - fst[b]; segtree[c] = segtree[a] + segtree[b] + steps * (rgt[a] - lft[a] + 1); fst[c] = fst[a] - steps; } void build(int node, int l, int r){ lft[node] = l; rgt[node] = r; if(l == r){ segtree[node] = 0; fst[node] = arr[l]; return; } int md = (l+r)/2; build(node*2, l, md); build(node*2+1, md+1, r); combine(node, node*2, node*2+1); } int _count(int n){ int c = 0; while(n > 0){ c += n&1; n /= 2; } return c; } pll solve(int a, pll pa, int b, pll pb, int qlow, int qhigh){ ll x = arr[rgt[a]]; ll y = pb.ss; if(x <= y){ return {pa.ff+pb.ff, pa.ss}; } ll steps = x - y; ll ans1 = pa.ff + pb.ff + steps * (rgt[a] - max(lft[a], qlow) + 1); return {ans1 ,pa.ss - steps}; } pll query(int node, int qlow, int qhigh, int l, int r){ if(r < qlow || l > qhigh){ return {-1, 0}; } if(l >= qlow && r <= qhigh){ return {segtree[node], fst[node]}; } int md = (l+r)/2; pll a = query(node*2, qlow, qhigh, l, md); pll b = query(node*2+1, qlow, qhigh, md+1, r); if(a.ff == -1)return b; if(b.ff == -1)return a; return solve(node*2, a, node*2+1, b, qlow, qhigh); } int32_t main(){ speed; ll d; int n;cin >> n >> d; for(int i = 0; i < n;i++){ cin >> arr[i]; } while(_count(n) != 1){ n++; } build(1, 0, n-1); /*for(int i = 1; i < 2*n;i++){ cout << i << " " << segtree[i] << " : " << fst[i] << endl; }*/ int q;cin >> q; while(q--){ int l, r;cin >> l >> r;l--;r--; /*ll done = 0; bool ok = 1; ll ans = 0; ll nxt = arr[r]; for(int i = r-1;i >= l;i--){ if(arr[i] <= nxt){ nxt = arr[i]; continue; } ll diff = arr[i] - nxt; ll steps = ceil((ld)diff / d); ll nw = arr[i] - d*steps; if(nw < 0){ok = 0;break;} ans += steps; nxt = nw; } cout << (ok ? ans : -1) << endl;*/ // cout << segtree[4] << endl; cout << query(1, l, r, 0, n-1).ff << endl; } } /* NEVER GIVE UP! DOING SMTHNG IS BETTER THAN DOING NTHNG!!! Your Guide when stuck: - Continue keyword only after reading the whole input - Don't use memset with testcases - Check for corner cases(n=1, n=0) - Check where you declare n(Be careful of declaring it globally and in main) */

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void usaco_problem()':
Main.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen("milkvisits.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     freopen("milkvisits.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void init()':
Main.cpp:40:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:42:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 | freopen("output.txt", "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...