Submission #894695

#TimeUsernameProblemLanguageResultExecution timeMemory
894695AgentPengin역사적 조사 (JOI14_historical)C++17
40 / 100
4049 ms9172 KiB
/** * author: AgentPengin ( Độc cô cầu bại ) * created: 23.12.2022 10:08:02 * too lazy to update time **/ #pragma GCC optimize(3) #pragma GCC optimize("inline") #pragma GCC optimize("-fgcse") #pragma GCC target("avx","sse2") #pragma GCC optimize("-fgcse-lm") #pragma GCC optimize("-fipa-sra") #pragma GCC optimize("-ftree-pre") #pragma GCC optimize("-ftree-vrp") #pragma GCC optimize("-fpeephole2") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-fsched-spec") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define EL '\n' #define fi first #define se second #define NAME "TASK" #define ll long long #define lcm(a,b) (a/gcd(a,b))*b #define db(val) "["#val" = " << (val) << "] " #define bend(v) (v).begin(),(v).end() #define sz(v) (int)(v).size() #define ex exit(0) using namespace std; const ll mod = 1e9 + 7; const int inf = 0x1FFFFFFF; const int MAXN = 1e5 + 5; const int BLOCK_SIZE = 400; struct Queries { int l,r,id; } query[MAXN]; int n,a[MAXN],b[MAXN],c[MAXN],q,L = 1,R = 0; vector<int> values; ll st[MAXN << 2]; ll ans[MAXN]; void update(int pos,int val,int id = 1,int l = 0,int r = sz(values) - 1) { if (pos < l || pos > r) return; if (l == r) { st[id] += (ll)val; return; } int mid = l + r >> 1; if (pos <= mid) update(pos,val,id << 1,l,mid); else update(pos,val,id << 1 | 1,mid + 1,r); st[id] = max(st[id << 1],st[id << 1 | 1]); } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); if (ifstream(NAME".inp")) { freopen(NAME".inp","r",stdin); freopen(NAME".out","w",stdout); } cin >> n >> q; for (int i = 1;i <= n;i++) { cin >> a[i]; values.push_back(a[i]); } sort(bend(values)); for (int i = 1;i <= n;i++) { b[i] = lower_bound(bend(values),a[i]) - values.begin(); c[b[i]] = a[i]; } for (int i = 1;i <=q ;i++) { cin >> query[i].l >> query[i].r; query[i].id = i; } sort(query + 1,query + q + 1,[&](const Queries& A,const Queries& B){ if (A.l / BLOCK_SIZE != B.l / BLOCK_SIZE) return A.l / BLOCK_SIZE < B.l / BLOCK_SIZE; else return A.r < B.r; }); for (int i = 1;i <= q;i++) { int l = query[i].l; int r = query[i].r; int id = query[i].id; while(L < l) { update(b[L],-values[b[L]]); ++L; } while(L > l) { --L; update(b[L],+values[b[L]]); } while(R < r) { ++R; update(b[R],+values[b[R]]); } while(R > r) { update(b[R],-values[b[R]]); --R; } ans[id] = st[1]; } for (int i = 1;i <= q;i++) cout << ans[i] << EL; cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; } // agent pengin wants to take apio (with anya-san)

Compilation message (stderr)

historic.cpp: In function 'void update(int, int, int, int, int)':
historic.cpp:53:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |  int mid = l + r >> 1;
      |            ~~^~~
historic.cpp: In function 'int main()':
historic.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen(NAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
historic.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(NAME".out","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...