Submission #26739

# Submission time Handle Problem Language Result Execution time Memory
26739 2017-07-05T10:57:17 Z model_code Meteors (POI11_met) C++11
100 / 100
2843 ms 60496 KB
/*************************************************************************
 *                                                                       *
 *                    XVIII Olimpiada Informatyczna                      *
 *                                                                       *
 *   Zadanie:           Meteory                                          *
 *   Autor:             Piotr Niedzwiedz                                 *
 *   Zlozonosc czasowa: O((n*lg(n)+(m+k)*lg(m))*lg(k))                   *
 *   Opis:              Rozwiazanie alternatywne                         *
 *                                                                       *
 *************************************************************************/


// headers {{{
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cctype>
#include <cstring>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long double LD;
typedef long long LL;
typedef pair<LD,LD> PD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<string> VS;

#define VAR(v,n) __typeof(n) v=(n)
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define FORD(i,a,b) for(int i=(a); i>=(b); i--)
#define FORE(i,c) for(VAR(i,(c).begin()); i!=(c).end(); i++)

#define ALL(x) x.begin(),x.end()
#define CLR(A,v) memset((A),v,sizeof((A)))
#define FI first
#define MP make_pair
#define PB push_back
#define SE second
#define SIZE(x) ((int)(x).size())
// }}}

const int nmx=300007,kmx=300007;
LL POW_TREE[nmx],max_pt;
inline int fun_pt(int x){return (((x-1)^x)+1) >> 1;}
void update_pt(int x,int vl)
{
	while (x <= max_pt) { POW_TREE[x]+=vl; x+=fun_pt(x);}	
}
LL pref_pt(int x)
{
	LL res=0;
	while(x) {res+=POW_TREE[x]; x-=fun_pt(x); }
	return res;
}
VI P[nmx];
int R[nmx];
int n, m, k;
int RR[kmx],LR[kmx],A[kmx];
int BSL[nmx],BSR[nmx],BSG[nmx];

VI S[nmx];

void add_range(int l,int r,int a) {
  if(l<=r) {
    update_pt(l,a);
    update_pt(r+1,-a);
  } else {
    add_range(1,r,a);
    add_range(l,m,a);
  }
}

bool binsearch(){
  bool found=0;
  REP(i,n) if(BSL[i] <= BSR[i]) {
    found=true;
    S[(BSL[i]+BSR[i])/2].PB(i);
  }
  if(!found) return 0;
  REP(i,k){
    add_range(LR[i],RR[i],A[i]);
    FORE(j, S[i+1]) {
      int g = *j;
      LL sum = 0;
      FORE(p, P[g]) {
        if(sum >= R[g]) break;
        sum+=pref_pt(*p);
      }
      if (sum >= R[g]) {
        BSG[g]=i+1;
        BSR[g]=i;
      } else {
        BSL[g]=i+2;
      }

    }
  }
  CLR(POW_TREE,0);
  FOR(i,1,k) S[i].clear();
  return true;
}


int main() {
  int a;
  scanf("%d%d",&n,&m);
  max_pt = m+2;
  REP(i,m) {
    scanf("%d",&a);
    P[a-1].PB(i+1);
  }
  REP(i,n) scanf("%d",R+i);
  scanf("%d",&k);
  REP(i,k) scanf("%d%d%d",LR+i,RR+i,A+i);
  CLR(BSG,-1);
  REP(i,n) BSL[i]=1,BSR[i]=k;
  while(binsearch());
  REP(i,n) {
    if(BSG[i]==-1) puts("NIE");
    else printf("%d\n",BSG[i]);

  }
  return 0;
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:124:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&n,&m);
                      ^
met.cpp:127:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&a);
                   ^
met.cpp:130:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   REP(i,n) scanf("%d",R+i);
                           ^
met.cpp:131:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&k);
                 ^
met.cpp:132:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   REP(i,k) scanf("%d%d%d",LR+i,RR+i,A+i);
                                         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 26628 KB Output is correct
2 Correct 9 ms 26628 KB Output is correct
3 Correct 3 ms 26628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 26628 KB Output is correct
2 Correct 3 ms 26628 KB Output is correct
3 Correct 6 ms 26760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 27496 KB Output is correct
2 Correct 189 ms 29496 KB Output is correct
3 Correct 173 ms 28892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 153 ms 28352 KB Output is correct
2 Correct 173 ms 28360 KB Output is correct
3 Correct 186 ms 29604 KB Output is correct
4 Correct 39 ms 28368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 27824 KB Output is correct
2 Correct 156 ms 29864 KB Output is correct
3 Correct 73 ms 26760 KB Output is correct
4 Correct 169 ms 29212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 27052 KB Output is correct
2 Correct 159 ms 28364 KB Output is correct
3 Correct 126 ms 27288 KB Output is correct
4 Correct 236 ms 30448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1759 ms 39928 KB Output is correct
2 Correct 873 ms 29280 KB Output is correct
3 Correct 376 ms 26760 KB Output is correct
4 Correct 2843 ms 56788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1639 ms 39372 KB Output is correct
2 Correct 889 ms 28764 KB Output is correct
3 Correct 286 ms 26760 KB Output is correct
4 Correct 2753 ms 60496 KB Output is correct