vector<int> countOfSmallerNumber(vector<int> &A, vector<int> &queries) {
     // write your code here
     sort(A.begin(), A.end());
     vector<int> ans;
     for(auto q:queries) {
         ans.push_back(findq(A, q));
     }
     return ans;
 }
Example #2
0
/*-------------------------------------------------------------------------*/
void main ()
{
   clrscr();
   k=find_k();
   printf("koren yravneniya : %f\n",k);
   getch();
   printf("Strelba:\n");
   strelba();
   getch();
   graphik();
   clrscr();
   findq();
   getch();
   printrez();
}
Example #3
0
void CleanupTask::CleanupProgramListings(void)
{
    MSqlQuery query(MSqlQuery::InitCon());
    QString querystr;
    // Keep as many days of listings data as we keep matching, non-recorded
    // oldrecorded entries to allow for easier post-mortem analysis
    int offset = gCoreContext->GetNumSetting( "CleanOldRecorded", 10);
    // Also make sure to keep enough data so that we can flag the original
    // airdate, for when that isn't included in guide data
    int newEpiWindow = gCoreContext->GetNumSetting( "NewEpisodeWindow", 14);
    if (newEpiWindow > offset)
        offset = newEpiWindow;

    query.prepare("DELETE FROM oldprogram WHERE airdate < "
                  "DATE_SUB(CURRENT_DATE, INTERVAL 320 DAY);");
    if (!query.exec())
        MythDB::DBError("HouseKeeper Cleaning Program Listings", query);

    query.prepare("REPLACE INTO oldprogram (oldtitle,airdate) "
                  "SELECT title,starttime FROM program "
                  "WHERE starttime < NOW() AND manualid = 0 "
                  "GROUP BY title;");
    if (!query.exec())
        MythDB::DBError("HouseKeeper Cleaning Program Listings", query);

    query.prepare("DELETE FROM program WHERE starttime <= "
                  "DATE_SUB(CURRENT_DATE, INTERVAL :OFFSET DAY);");
    query.bindValue(":OFFSET", offset);
    if (!query.exec())
        MythDB::DBError("HouseKeeper Cleaning Program Listings", query);

    query.prepare("DELETE FROM programrating WHERE starttime <= "
                  "DATE_SUB(CURRENT_DATE, INTERVAL :OFFSET DAY);");
    query.bindValue(":OFFSET", offset);
    if (!query.exec())
        MythDB::DBError("HouseKeeper Cleaning Program Listings", query);

    query.prepare("DELETE FROM programgenres WHERE starttime <= "
                  "DATE_SUB(CURRENT_DATE, INTERVAL :OFFSET DAY);");
    query.bindValue(":OFFSET", offset);
    if (!query.exec())
        MythDB::DBError("HouseKeeper Cleaning Program Listings", query);

    query.prepare("DELETE FROM credits WHERE starttime <= "
                  "DATE_SUB(CURRENT_DATE, INTERVAL :OFFSET DAY);");
    query.bindValue(":OFFSET", offset);
    if (!query.exec())
        MythDB::DBError("HouseKeeper Cleaning Program Listings", query);

    query.prepare("DELETE FROM record WHERE (type = :SINGLE "
                  "OR type = :OVERRIDE OR type = :DONTRECORD) "
                  "AND enddate < CURDATE();");
    query.bindValue(":SINGLE", kSingleRecord);
    query.bindValue(":OVERRIDE", kOverrideRecord);
    query.bindValue(":DONTRECORD", kDontRecord);
    if (!query.exec())
        MythDB::DBError("HouseKeeper Cleaning Program Listings", query);

    MSqlQuery findq(MSqlQuery::InitCon());
    findq.prepare("SELECT record.recordid FROM record "
                  "LEFT JOIN oldfind ON oldfind.recordid = record.recordid "
                  "WHERE type = :FINDONE AND oldfind.findid IS NOT NULL;");
    findq.bindValue(":FINDONE", kOneRecord);

    if (findq.exec())
    {
        query.prepare("DELETE FROM record WHERE recordid = :RECORDID;");
        while (findq.next())
        {
            query.bindValue(":RECORDID", findq.value(0).toInt());
            if (!query.exec())
                MythDB::DBError("HouseKeeper Cleaning Program Listings", query);
        }
    }
    query.prepare("DELETE FROM oldfind WHERE findid < TO_DAYS(NOW()) - 14;");
    if (!query.exec())
        MythDB::DBError("HouseKeeper Cleaning Program Listings", query);

    query.prepare("DELETE FROM oldrecorded WHERE "
                  "recstatus <> :RECORDED AND duplicate = 0 AND "
                  "endtime < DATE_SUB(CURRENT_DATE, INTERVAL :CLEAN DAY);");
    query.bindValue(":RECORDED", rsRecorded);
    query.bindValue(":CLEAN", offset);
    if (!query.exec())
        MythDB::DBError("HouseKeeper Cleaning Program Listings", query);
}
Example #4
0
int msgq::queuescan2(std::string s)
{
	DIR *tmpdir=opendir(s.c_str());
	struct dirent *de;
	std::list<std::string>	filename_list;

	if (!tmpdir)	clog_msg_errno();

	while ((de=readdir(tmpdir)) != 0)
	{
	const char *p=de->d_name;

		if (*p++ != 'C')	continue;

	ino_t	inum=strtoino(p);

		// Perhaps this one's in the queue already

		if (findq(inum))	continue;	// Already in msgq

		while (isdigit(*p))	p++;
		if (*p++ != '.')	continue;

		while (isdigit(*p))
			++p;

		if (*p)	continue;

		filename_list.push_back(de->d_name);
	}
	closedir(tmpdir);

	if (filename_list.size() == 0)
		return (1);	// Pretend we added something, so keep going

	std::vector<std::string> filename_array;

	filename_array.reserve(filename_list.size());

	filename_array.insert(filename_array.end(),
			      filename_list.begin(), filename_list.end());

	int	rc;
	int	flag=0;

	std::sort(filename_array.begin(), filename_array.end(),
		  std::ptr_fun(sort_by_qtime));


	std::vector<std::string>::iterator b, e;

	b=filename_array.begin();
	e=filename_array.end();

	while (b != e)
	{
		rc=queuescan3(s, *b++, 0);

		if (rc < 0)
			return (-1);
		if (rc)	break;
		flag=1;
	}
	return (flag);
}