제출 #222857

#제출 시각아이디문제언어결과실행 시간메모리
222857arnold518운세 보기 2 (JOI14_fortune_telling2)C++14
100 / 100
772 ms51212 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2e5; int N, M; pii A[MAXN+10]; int B[MAXN+10]; ll ans; vector<int> tree[MAXN*4+10]; void init(int node, int tl, int tr) { if(tl==tr) { tree[node].push_back(B[tl]); return; } int mid=tl+tr>>1; init(node*2, tl, mid); init(node*2+1, mid+1, tr); tree[node].resize(tree[node*2].size()+tree[node*2+1].size()); merge(tree[node*2].begin(), tree[node*2].end(), tree[node*2+1].begin(), tree[node*2+1].end(), tree[node].begin()); } int query1(int node, int tl, int tr, int l, int r) { if(tl==tr) return tl; int mid=tl+tr>>1; if(lower_bound(tree[node*2+1].begin(), tree[node*2+1].end(), r)-lower_bound(tree[node*2+1].begin(), tree[node*2+1].end(), l)) return query1(node*2+1, mid+1, tr, l, r); else return query1(node*2, tl, mid, l, r); } int query2(int node, int tl, int tr, int l, int r, int k) { if(r<tl || tr<l) return 0; if(l<=tl && tr<=r) return tree[node].end()-lower_bound(tree[node].begin(), tree[node].end(), k); int mid=tl+tr>>1; return query2(node*2, tl, mid, l, r, k)+query2(node*2+1, mid+1, tr, l, r, k); } int main() { int i, j; scanf("%d%d", &N, &M); for(i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second); for(i=1; i<=M; i++) scanf("%d", &B[i]); init(1, 1, M); for(i=1; i<=N; i++) { int l=A[i].first, r=A[i].second; if(l>r) swap(l, r); int t=lower_bound(tree[1].begin(), tree[1].end(), r)-lower_bound(tree[1].begin(), tree[1].end(), l); if(t) { int p=query1(1, 1, M, l, r); int q=query2(1, 1, M, p+1, M, r); if(q%2) ans+=l; else ans+=r; } else { int q=query2(1, 1, M, 1, M, r); if(q%2) ans+=A[i].second; else ans+=A[i].first; } } printf("%lld\n", ans); }

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

fortune_telling2.cpp: In function 'void init(int, int, int)':
fortune_telling2.cpp:24:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=tl+tr>>1;
          ~~^~~
fortune_telling2.cpp: In function 'int query1(int, int, int, int, int)':
fortune_telling2.cpp:34:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=tl+tr>>1;
          ~~^~~
fortune_telling2.cpp: In function 'int query2(int, int, int, int, int, int)':
fortune_telling2.cpp:43:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=tl+tr>>1;
          ~~^~~
fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:49:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
fortune_telling2.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
fortune_telling2.cpp:52:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=N; i++) scanf("%d%d", &A[i].first, &A[i].second);
                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:53:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=M; i++) scanf("%d", &B[i]);
                      ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...